1

I refer to this link

http://developer.android.com/training/in-app-billing/list-iab-products.html

Dear All, I have to show the price of in-app products of my app from google play. Although I tried to get prices from google play as shown in link above... There is an error at

" for (String thisResponse : responseList) { "

telling that

"Type mismatch: cannot convert from element type Object to String".

how can i solve this error? or which way can I get in-app product price from google play?

Here is my code.

    ArrayList skuList = new ArrayList();
    skuList.add("000001");
    skuList.add("gas");
    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
    String mPackagePrice;

    try {
        Bundle skuDetails = mService.getSkuDetails(3, 
                   getPackageName(), "inapp", querySkus);

        int response = skuDetails.getInt("RESPONSE_CODE");
        if (response == 0) {
           ArrayList responseList 
              = skuDetails.getStringArrayList("DETAILS_LIST");

           for (String thisResponse : responseList) {

              JSONObject object = new JSONObject(thisResponse);
              String sku = object.getString("productId");
              String price = object.getString("price");
              if (sku.equals("000001")) mPackagePrice = price;
           }
        }

    } catch (RemoteException e) {
        e.printStackTrace();
    }
rajeshwaran
  • 1,512
  • 1
  • 18
  • 24
John Nash
  • 192
  • 2
  • 10

2 Answers2

0

You can't leave the ArrayList generic:

ArrayList<String> skuList = new ArrayList<String>();

and

ArrayList<String> responseList = ...
323go
  • 14,143
  • 6
  • 33
  • 41
0

Just as "323go", it will solve your issue but after, if you are using Eclipse it will ask you to surround this part with try/catch also to handle jsonException:

    } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }

Them you will be fine.

Totalys
  • 445
  • 2
  • 10
  • 25