i have fetched data from my api but i don't know how to assign this fetched data to my adapter?
Issue:
how to set fetched data to array defined above?
how to set an adapter ?
public class FetchLists extends AsyncTask<>{
public List<MailChimpList> listTitles = new ArrayList<>();
#Override
protected List<MailChimpList> doInBackground(Integer... params) {
int count = params[0];
int offset = params[1];
String urlString = "https://us14.api.mailchimp.com/lists?apikey=efb918ee8791215bac4c8a3a8a77-us14"
urlString = urlString + "&count=" + count + "&offset=" + offset;
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
InputStream stream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line = reader.readLine();
String response = "";
while (line != null) {
response += line;
line = reader.readLine();
}
JSONObject object = new JSONObject(response);
JSONArray lists = object.getJSONArray("lists");
for (int i = 0; i < lists.length(); i++) {
JSONObject listData = (JSONObject) lists.get(i);
MailChimpList mailChimpList = new MailChimpList();
mailChimpList.id = listData.getString("id");
mailChimpList.title = listData.getString("name");
String id = listData.getString("id");
String title = listData.getString("name");
Log.d("ashutosh","id are: "+id);
Log.d("ashutosh","list name are: "+title);
listTitles.add(mailChimpList);
}
} catch (Exception e) {
e.printStackTrace();
}
return listTitles;
}
#Override
protected void onPostExecute(List<MailChimpList> mailChimpLists) {
}
}
#Override
protected void onPostExecute(List<MailChimpList> mailChimpLists) {
MyCustomAdapter adapter = new MyCustomAdapter(context, mailChimpLists);
myListView.setAdapter(adapter);
}
As your list is customized list you need to write a customer adapter
You can declare your ListView as global variable and it can be accessed in post execute.
Related
i have classes in my projects that only does the server operations such as getting and putting data. i have class which populating list and then method to get this list. the problem is that i'm calling the "getList" method and the background operation hasent finished then i get null from the "getList" method
this is my AsyncTask class, as you can see the "getList" suppose to give me the list completed
public class GetRoomatesListActivity extends AsyncTask<String, String, String> {
private ArrayList<RoomateModel> tmpList;
private ArrayList<RoomateModel> completeList;
DBHelper db;
Context context;
public GetRoomatesListActivity(Context context){
this.context = context;
}
#Override
protected String doInBackground(String... params) {
db = DBHelper.getInstance(context);
HttpURLConnection connection = null;
BufferedReader reader = null;
tmpList = new ArrayList<RoomateModel>();
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String finalJson = buffer.toString();
JSONObject parentObject = new JSONObject(finalJson);
JSONArray parentArray = parentObject.getJSONArray("result");//creates array of Roomates of the selected apartment
for (int i = 0; i < parentArray.length(); i++) {
JSONObject finalObject = parentArray.getJSONObject(i);//get the cuttent json object which is representaion of roomate object
String Fname = finalObject.getString("firstName");
String Lname = finalObject.getString("lastName");
String phone = finalObject.getString("phone");
RoomateModel item = new RoomateModel(Fname, Lname, phone);//creates roomates model with the current item data from the array
tmpList.add(item);//adds the roomate to the list of roomates
//add the roomates to local data base
db.addRoomate(item,apartment);
}
return null;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
completeList = tmpList;
}
public ArrayList<RoomateModel> getList(){
return completeList;
}
}
and this is the class which im trying to get the list to in order to use it but its retrieving null
public class roomatesScreen extends Activity {
ListView items;
ArrayList<RoomateModel> list; //list to compare with the list rerived from GetRoomatesListActivity
RoomatesAdapter adapter;
DBHelper db;
ApartmentModel apartment;
SharedPreferences preferences;
GetRoomatesListActivity r;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.roomates_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
items = (ListView) findViewById(R.id.roomatesList);
db = DBHelper.getInstance(this);
Bundle bundle = getIntent().getExtras();
int number = bundle.getInt("number");
apartment = new ApartmentModel(number);// creates apartment model with the user's apartment number
final String num = Integer.toString(number);
r = new GetRoomatesListActivity(this);
r.execute("this is the link to my query" + num);
list = r.getList(); //here list is null
adapter = new RoomatesAdapter(roomatesScreen.this, list);
items.setAdapter(adapter);//here application crushes because of nullPointerExpeption
The best way is to perform the update on UI is in PostExecute method of AsyncTask..
At the time you are accessing it, the control is in the doInBackground method. So your list is null at that time.
put this
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
adapter = new RoomatesAdapter(roomatesScreen.this, tmpList);
items.setAdapter(adapter);/
}
into the onPostExecute().
2nd solution
Initialize the list when you are setting it to adapter. like:
list = new ArrayList();
and rest work (update the list and call notifyDataSetChanged() on adapter object) in onPostExecute().
Change doInBackground() method return type
public class GetRoomatesListActivity extends AsyncTask<String, String, ArrayList<Object>> {
private ArrayList<RoomateModel> tmpList;
private ArrayList<RoomateModel> completeList;
DBHelper db;
Context context;
public GetRoomatesListActivity(Context context){
this.context = context;
}
#Override
protected ArrayList<Object> doInBackground(String... params) {
db = DBHelper.getInstance(context);
HttpURLConnection connection = null;
BufferedReader reader = null;
tmpList = new ArrayList<RoomateModel>();
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String finalJson = buffer.toString();
JSONObject parentObject = new JSONObject(finalJson);
JSONArray parentArray = parentObject.getJSONArray("result");//creates array of Roomates of the selected apartment
for (int i = 0; i < parentArray.length(); i++) {
JSONObject finalObject = parentArray.getJSONObject(i);//get the cuttent json object which is representaion of roomate object
String Fname = finalObject.getString("firstName");
String Lname = finalObject.getString("lastName");
String phone = finalObject.getString("phone");
RoomateModel item = new RoomateModel(Fname, Lname, phone);//creates roomates model with the current item data from the array
tmpList.add(item);//adds the roomate to the list of roomates
//add the roomates to local data base
db.addRoomate(item,apartment);
}
return null;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
completeList = tmpList;
}
public ArrayList<RoomateModel> getList(){
return completeList;
}
}
I'm trying to get the values from my mySql database and display them in a listView. However when I click the button to display them I get the following error message : org.json.JSONException: No value for establishments.
I know that the TAG_RESULTS is empty but I don't know what I'm supposed to put in to it.
Here is my code
public class SecondPage extends AppCompatActivity {
String myJSON;
//There is no value for this TAG_RESULTS ON LINE 116
private static final String TAG_RESULTS="establishments";
private static final String TAG_NAME = "name";
private static final String TAG_PICTURE = "picture";
JSONArray establishments_JSON = null;
ArrayList<HashMap<String, String>> establishmentsList;
//JSONArray establishments = null;
//Array establishments = null;
ListView listView ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.current_location_listview);
listView = (ListView) findViewById(R.id.listView);
establishmentsList = new ArrayList<HashMap<String,String>>();
getData();
}
public void getData(){
//changed the middle parameter to a string from a void
class GetDataJSON extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
Log.d("GETTING JSON DATA", "HERE....");
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://10.102.11.109/findandeat_xampp_data/get_all_establishments.php");
//String loginDetails = ServerConnection.RUSH_SERVER_ADDRESS + "login.php?userName=" + userNameInput + "&password=" + passwordInput;
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
Log.d("STARTING INPUT STREAM", "HERE....");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
result = sb.toString();
} catch (Exception e) {
// Oops
Log.d("CATCH ANY ERRORS", "HERE....");
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
#Override
protected void onPostExecute(String result){
myJSON=result;
Log.d("myjson",myJSON);
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
protected void showList(){
try {
Log.d("myjson",myJSON);
JSONObject jsonObj = new JSONObject(myJSON);
establishments_JSON = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<establishments_JSON.length();i++){
JSONObject c = establishments_JSON.getJSONObject(i);
String pizzeriaName = c.getString(TAG_NAME);
String pizzeriaPicture = c.getString(TAG_PICTURE);
String chineseName = c.getString(TAG_NAME);
String chinesePicture = c.getString(TAG_PICTURE);
String cafeName = c.getString(TAG_NAME);
String cafePicture = c.getString(TAG_PICTURE);
String indianName = c.getString(TAG_NAME);
String indianPicture = c.getString(TAG_PICTURE);
String ChipShopName = c.getString(TAG_NAME);
String ChipShopPicture = c.getString(TAG_PICTURE);
//Error im getting is that there is no value for the result
//with the JSON
HashMap<String,String> establishment_items = new HashMap<String,String>();
establishment_items.put(TAG_NAME,pizzeriaName);
establishment_items.put(TAG_PICTURE,pizzeriaPicture);
establishment_items.put(TAG_NAME,chineseName);
establishment_items.put(TAG_PICTURE,chinesePicture);
establishment_items.put(TAG_NAME,cafeName);
establishment_items.put(TAG_PICTURE,cafePicture);
establishment_items.put(TAG_NAME,indianName);
establishment_items.put(TAG_PICTURE,indianPicture);
establishment_items.put(TAG_NAME,ChipShopName);
establishment_items.put(TAG_PICTURE,ChipShopPicture);
establishmentsList.add(establishment_items);
}
ListAdapter adapter = new SimpleAdapter(
SecondPage.this, establishmentsList, R.layout.activity_current_location_items,
new String[]{TAG_NAME,TAG_PICTURE},
new int[]{R.id.establishment_name, R.id.establishment_picture}
);
listView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
XMLdatabase column names
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView" />
column name in database
The other types of restuarants have the same naming system applied
It will generate this error because there is the parameter you want. So you can validate:
//if exists
if(jsonObj.has(TAG_RESULTS)){
}
The same should do to verify certain parameters exist or not in the JSON object, so you save trouble with exceptions.
use .has(String) and isNull(String)
.has(String) checks if the JSONObject contains a specific key
.isNull(String) checks if the value associated with the key is null or if there is no value
So , your code will be
if (jsonObj.has(TAG_RESULTS) && !jsonObj.isNull(TAG_RESULTS)) {
establishments_JSON = jsonObj.getJSONArray(TAG_RESULTS);
}
I hope to be helpful for you .
I am trying to click a hyperlink and call method in android programming...
But the problem is , the link is not showing up and neither the method is getting called. How to achieve this result?
I am basically a javascript/jsp developer, this is my first android application , which i am learning. Accordingly i am trying to click link and call method with parameter....
Results looking like
Java code
private class CallAPI extends AsyncTask<String, String, String> {
private String Content;
#Override
protected String doInBackground(String... params) {
String urlString=params[0]; // URL to call
String resultToDisplay = "";
InputStream in = null;
emailVerificationResult result = null;
// HTTP Get
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream());
System.out.println("test");
BufferedReader reader = null;
// Get the server response
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while ((line = reader.readLine()) != null) {
// Append server response in string
sb.append(line + "\n");
}
// Append Server Response To Content String
Content = sb.toString();
} catch (Exception e ) {
System.out.println(e.getMessage());
return e.getMessage();
}
/****************** Start Parse Response JSON Data *************/
String OutputData = "<center><b><u>Weight Training</u></b></center><br/><br/>";
JSONObject jsonResponse;
try {
/****** Creates a new JSONObject with name/value mappings from the JSON string. ********/
jsonResponse = new JSONObject(Content);
/***** Returns the value mapped by name if it exists and is a JSONArray. ***/
/******* Returns null otherwise. *******/
JSONArray jsonMainNode = jsonResponse.optJSONArray("articleList");
/*********** Process each JSON Node ************/
int lengthJsonArr = jsonMainNode.length();
for (int i = 0; i < lengthJsonArr; i++) {
/****** Get Object for each JSON node.***********/
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
/******* Fetch node values **********/
String name = jsonChildNode.optString("menu_name").toString();
String number = jsonChildNode.optString("id").toString();
String date_added = jsonChildNode.optString("parent_id").toString();
OutputData += " " +
String.format("<a onClick='verifyEmail("+number+","+date_added+")'><b>"+name+"<b> "+ number+" "+ date_added+"</a> ") +"<br/><br/>";
}
/****************** End Parse Response JSON Data *************/
/* Show Parsed Output on screen (activity) */
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
resultToDisplay =OutputData ;
return resultToDisplay;
}
// This is the method that is called when the submit button is clicked
public void verifyEmail(String m,String p) {
String urlString = apiURL + "mid=" + m + "&pid=" + p;
new CallAPI().execute(urlString);
}
protected void onPostExecute(String result) {
Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
intent.putExtra(EXTRA_MESSAGE, result);
startActivity(intent);
}
Update:
Instead of link, can i put a button and provide on click method and pass parameter to the method
(Thankfully) You cannot call a function using HTML tags in android. Instead try setting ClickableSpan on you you TextView to get the desired effect
SpannableString ss = new SpannableString("Click Me to do magic");
ClickableSpan clickableSpan = new ClickableSpan() {
#Override
public void onClick(View textView) {
doSomeMagic();
}
#Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
};
// apply the clickable span on "Click Me" part which is on index 0 -> 7
// 8 is used because it goes from a -> b-1
ss.setSpan(clickableSpan, 0, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView textView = (TextView) findViewById(R.id.foo);
textView.setText(ss);
I know I've overlooked something minor here - but I can't seem to populate my list view using the JSON data I've managed to parse out - I've debugged it and I have data for all my strings - but for some reason the listView isn't populating and I'm not sure what I've overlooked:
Source:
#Override
protected String doInBackground(String... arg0) {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url)
.openConnection();
InputStream is = conn.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
for (String line = r.readLine(); line != null; line = r
.readLine()) {
sb.append(line);
}
JSONArray jsonArray = new JSONArray(sb.toString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject cO = jsonArray.getJSONObject(i);
String value1 = cO.getString("field1");
JSONObject oC = cO.getJSONObject("itema");
String value2 = oC.getString("field2");
JSONObject oA = oC.getJSONObject("itemb");
String value3 = oA.getString("field3");
final JSONAdapter jSONAdapter;
jSONAdapter = new JSONAdapter(Example.this, jsonArray);
runOnUiThread(new Runnable() {
#Override
public void run() {
final ListView list;
list = (ListView) findViewById(R.id.list);
list.setAdapter(jSONAdapter);
}
});
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
I suggest you do the following.
First: AsyncTask's onPostExecute runs on the main thread, and you should use that instead. Let doInBackground return a List<String>
public class MyAsyncTask extends AsyncTask<Void,Void,List<String>> {
private String url;
public MyAsyncTask(String url) {
this.url = url;
}
#Override
protected List<String> doInBackground(Void... arg0) {
List<String> result = new ArrayList<String>();
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url)
.openConnection();
InputStream is = conn.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
for (String line = r.readLine(); line != null; line = r
.readLine()) {
sb.append(line);
}
JSONArray jsonArray = new JSONArray(sb.toString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject cO = jsonArray.getJSONObject(i);
String value1 = cO.getString("field1");
JSONObject oC = cO.getJSONObject("itema");
String value2 = oC.getString("field2");
JSONObject oA = oC.getJSONObject("itemb");
String value3 = oA.getString("field3");
//format how you want to output each row;
result.add(value1 + " " + value2 + " - " + value3);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return result;
}
#Override
protected void onPostExecute(List<String> list) {
ListView lv = (ListView) findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Example.this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
}
}
This means the signature of your AsyncTask becomes AsyncTask<Void, Void, List<String>> if i'm not mistaken. What actually happens is this: you extract the strings per entry in the jsonarray. Then you add it to your list. The you return the list, and it is passed into the onPostExecute(List<String>). Then, we find the listview, create an ArrayAdapter<String>, and set android.R.layout.simple_list_item_1 as the layout each String is projected on, and we also set the list as the thing the arrayadapter should be projecting.
After that, we set the adapter.
EDIT: The signature of the asynctask should be
public class MyAsyncTask extends AsyncTask<Void,Void, List<String>> {
public List<String> doInBackground(Void...args);
public void onPostExecute(List<String> list);
}
And to fix your fatal error:
return list, not null.
delete your empty doInBackground(Void...args) method
change doInBackgorund(String...args) to doInBackground(Void...args)
Or the full code
public class Example extends AsyncTask<Void,Void, List<String>> {
final String TAG = "AsyncTaskParseJson.java";
String url = "https://example.com";
protected List<String> doInBackground(Void... arg0) {
List<String> result = new ArrayList<String>();
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url)
.openConnection();
InputStream is = conn.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
for (String line = r.readLine(); line != null; line = r
.readLine()) {
sb.append(line);
}
JSONArray jsonArray = new JSONArray(sb.toString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject cO = jsonArray.getJSONObject(i);
String value1 = cO.getString("field1");
JSONObject oC = cO.getJSONObject("itema");
String value2 = oC.getString("field2");
JSONObject oA = oC.getJSONObject("itemb");
String value3 = oA.getString("field3");
//format how you want to output each row;
result.add(value1 + " " + value2 + " - " + value3);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return list;
}
protected void onPostExecute(List<String> list) {
ListView lv = (ListView) findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Example.this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
}
}
I am a beginner in Android, and I am writing a short program to download a JSON feed from URL and parse it. I use AsyncTask to do the downloading.
The doInBackground() part seems to work well. Then I set my breakpoint to onPostExecute(), it can even stop at parseJSON(result), and 'result' is showing the correct json string downloaded. But when I try to step into parseJSON(result), it will NOT step into the function correctly(either throw JSONException directly or go to some random lines within parseJSON(result)).
From DDMS log it's not showing any valuable information as well.
How might I find what the problem is? Is it because I used onPostExecute() incorrectly, or parseJSON() has some problem?
public class MainActivity extends Activity {
private listItem[] items;
public class listItem {
String title;
String description;
String imageHref;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
items = new listItem[50];
new DownloadJsonFeed().execute("http://dl.dropbox.com/u/10168342/facts.json");
}
private class DownloadJsonFeed extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
try {
return downloadUrl(params[0]);
} catch (IOException e) {
return "Unable to retrieve json feed. URL may be invalid.";
}
}
#Override
protected void onPostExecute(String result) {
try {
parseJSON(result); // Here !!!!!!
} catch (JSONException e) {
}
}
}
private String downloadUrl(String myurl) throws IOException {
InputStream is = null;
try {
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
// Convert the InputStream into a string
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
return sb.toString();
} finally {
if (is != null) {
is.close();
}
}
}
private void parseJSON(String feed) throws JSONException {
JSONObject json_obj = new JSONObject(feed);
title = json_obj.getString("title");
String rows = json_obj.getString("rows");
JSONArray jArray = new JSONArray(rows);
for (int i = 0; i < jArray.length(); i++) {
JSONObject tmp = jArray.getJSONObject(i);
items[i].title = tmp.getString("title");
items[i].description = tmp.getString("description");
items[i].imageHref = tmp.getString("imageHref");
}
}
JSONObject.getString() will try to get String type value, but what you want is array type.
I think you didn't get the JSON array right. The json_obj.getString will give you an String instead an array.
Try to change as follows:
private void parseJSON(String feed) throws JSONException {
JSONObject json_obj = new JSONObject(feed);
title = json_obj.getString("title");
String rows = json_obj.getString("rows");
JSONArray jArray = json_obj.getJSONArray("rows"); //<---- change this line
for (int i = 0; i < jArray.length(); i++) {
JSONObject tmp = jArray.getJSONObject(i);
items[i].title = tmp.getString("title");
items[i].description = tmp.getString("description");
items[i].imageHref = tmp.getString("imageHref");
}
}