unfortunately has stopped when I want to update ListView












0














My logic is as follows.
First, I get some data from the server. Then, I manipulate the data. Next, I put the data into a ListView. If the user scrolls to the bottom of this view, I want to refresh the view. I copy the properties from my Async object to a new object. At this point I see "unfortunately has stopped".



Here my code of activity class



    DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {


@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH,monthOfYear);

this.Syear = calendar.get(Calendar.YEAR);
this.Smonth = calendar.get(Calendar.MONTH);
Smonth = Smonth + 1;
InboxActivity i = new InboxActivity();

String user_id = getIntent().getExtras().getString(LoginActivity.SESSION_ID);

final FetchTask fetch = new FetchTask();
fetch.Selectedmonth = this.Smonth;
fetch.Selectedyear = this.Syear;
fetch.page = 0;
fetch.sess_id = user_id;
ListView ll = (ListView)findViewById(R.id.mailList);
fetch.ll = ll;
fetch.execute();

ll.setOnScrollListener(new OnScrollListener(){



@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
{
if(firstVisibleItem+visibleItemCount==totalItemCount)
{

//System.out.println("HERE WILL BE MY SESSION ID!!!!w");
//System.out.println(fetch.sess_id);

FetchTask RefreshFetch = new FetchTask();

fetch.page++;
RefreshFetch.page = fetch.page++;
RefreshFetch.Selectedmonth = fetch.Selectedmonth;
RefreshFetch.Selectedyear = fetch.Selectedyear;
RefreshFetch.sess_id = fetch.sess_id;
RefreshFetch.ll = fetch.ll;

RefreshFetch.execute();

}

}


});

}
};


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}



public class FetchTask extends AsyncTask<Void, Void, JSONArray> {

public JSONArray result_arr;
public String result_str,email,password,test;
public int Selectedyear;
public int Selectedmonth;
public int page;
public String sess_id;
public ListView ll;
public ProgressDialog pd;
public ArrayAdapter<String> adapter;


@Override

protected JSONArray doInBackground(Void... params) {
try {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("MY SITE URL ....");

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);



nameValuePairs.add(new BasicNameValuePair("qw", "das"));
nameValuePairs.add(new BasicNameValuePair("debug", "1"));
nameValuePairs.add(new BasicNameValuePair("t", "0"));
nameValuePairs.add(new BasicNameValuePair("m", Integer.toString(this.Selectedmonth)));
nameValuePairs.add(new BasicNameValuePair("y", Integer.toString(this.Selectedyear)));
nameValuePairs.add(new BasicNameValuePair("st", Integer.toString(this.page)));

nameValuePairs.add(new BasicNameValuePair("sess_id", this.sess_id));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine());
String line = "0";
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
reader.close();
String result11 = sb.toString();

this.result_str = result11;
// parsing data
JSONArray arr = new JSONArray(result11);





return new JSONArray(result11);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}



@Override
protected void onPreExecute() {

}


My logs



03-05 13:24:43.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 49K, 7% free 3326K/3540K, paused 33ms, total 35ms
03-05 13:24:43.629: D/gralloc_goldfish(2052): Emulator without GPU emulation detected.
03-05 13:24:50.349: D/dalvikvm(2052): GC_FOR_ALLOC freed 151K, 8% free 3690K/4004K, paused 28ms, total 36ms
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): KeyEvent: ACTION_UP but key was not down.
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): in android.widget.EditText{b1e53a20 VFED..CL .F....I. 179,489-589,548 #7f090004 app:id/password}
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): 0: sent at 11916532000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=11916532, downTime=11916440, deviceId=0, source=0x101 }
03-05 13:24:55.809: D/dalvikvm(2052): GC_FOR_ALLOC freed 417K, 14% free 3788K/4368K, paused 31ms, total 31ms
03-05 13:24:56.509: D/dalvikvm(2052): GC_FOR_ALLOC freed 89K, 12% free 3877K/4368K, paused 39ms, total 42ms
03-05 13:24:56.549: D/dalvikvm(2052): GC_FOR_ALLOC freed 28K, 12% free 3947K/4468K, paused 39ms, total 40ms
03-05 13:24:56.599: I/dalvikvm-heap(2052): Grow heap (frag case) to 5.087MB for 1127536-byte allocation
03-05 13:24:56.649: D/dalvikvm(2052): GC_FOR_ALLOC freed <1K, 10% free 5048K/5572K, paused 48ms, total 48ms
03-05 13:25:14.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 504K, 12% free 5273K/5940K, paused 56ms, total 58ms
03-05 13:25:15.319: I/Choreographer(2052): Skipped 125 frames! The application may be doing too much work on its main thread.
03-05 13:25:15.809: I/Choreographer(2052): Skipped 49 frames! The application may be doing too much work on its main thread.
03-05 13:25:16.209: I/Choreographer(2052): Skipped 34 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.249: I/Choreographer(2052): Skipped 87 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.599: I/Choreographer(2052): Skipped 35 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.239: I/Choreographer(2052): Skipped 37 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.659: I/Choreographer(2052): Skipped 42 frames! The application may be doing too much work on its main thread.
03-05 13:25:23.629: I/Choreographer(2052): Skipped 98 frames! The application may be doing too much work on its main thread.
03-05 13:25:24.819: D/AndroidRuntime(2052): Shutting down VM
03-05 13:25:24.819: W/dalvikvm(2052): threadid=1: thread exiting with uncaught exception (group=0xb1aefba8)
03-05 13:25:24.919: E/AndroidRuntime(2052): FATAL EXCEPTION: main
03-05 13:25:24.919: E/AndroidRuntime(2052): Process: com.example.earchive, PID: 2052
03-05 13:25:24.919: E/AndroidRuntime(2052): java.lang.NullPointerException
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:291)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:1)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Handler.dispatchMessage(Handler.java:102)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Looper.loop(Looper.java:136)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invoke(Method.java:515)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-05 13:25:24.919: E/AndroidRuntime(2052): at dalvik.system.NativeStart.main(Native Method)
03-05 13:25:26.259: D/dalvikvm(2052): GC_FOR_ALLOC freed 385K, 9% free 5692K/6240K, paused 145ms, total 145ms


On post execute method



protected void onPostExecute(JSONArray result)
{
if (result != null)
{
List<String> subjects = new ArrayList<String>();
List<String> emails = new ArrayList<String>();

for(int i = 0; i < result.length(); i++)
{
try
{
JSONObject json_data = result.getJSONObject(i);
emails.add(json_data.getString("mittente"));
subjects.add(json_data.getString("oggetto"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
if(this.page == 0)
{
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
else
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}
}
else
{
System.out.println("Messages not found");

}
this.pd.dismiss();
}


}










share|improve this question




















  • 2




    Post logcat output as well.
    – MysticMagicϡ
    Mar 5 '14 at 18:19










  • i'v done it check it please
    – user3323180
    Mar 5 '14 at 18:27










  • I tried to salvage the introductory paragraph, but it was so hard to understand that I may have made a mistake. I apologize if my interpretation was poor. Can you please narrow down the code to only the portions that are relevant? You shouldn't post your entire program on Stack and expect us to look through all of it.
    – Rainbolt
    Mar 5 '14 at 18:27






  • 2




    NullPointerException on line 291. That's what is causing it to crash. Don't listen to John, more code is better.
    – Spidy
    Mar 5 '14 at 18:29












  • i have done it John
    – user3323180
    Mar 5 '14 at 18:32
















0














My logic is as follows.
First, I get some data from the server. Then, I manipulate the data. Next, I put the data into a ListView. If the user scrolls to the bottom of this view, I want to refresh the view. I copy the properties from my Async object to a new object. At this point I see "unfortunately has stopped".



Here my code of activity class



    DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {


@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH,monthOfYear);

this.Syear = calendar.get(Calendar.YEAR);
this.Smonth = calendar.get(Calendar.MONTH);
Smonth = Smonth + 1;
InboxActivity i = new InboxActivity();

String user_id = getIntent().getExtras().getString(LoginActivity.SESSION_ID);

final FetchTask fetch = new FetchTask();
fetch.Selectedmonth = this.Smonth;
fetch.Selectedyear = this.Syear;
fetch.page = 0;
fetch.sess_id = user_id;
ListView ll = (ListView)findViewById(R.id.mailList);
fetch.ll = ll;
fetch.execute();

ll.setOnScrollListener(new OnScrollListener(){



@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
{
if(firstVisibleItem+visibleItemCount==totalItemCount)
{

//System.out.println("HERE WILL BE MY SESSION ID!!!!w");
//System.out.println(fetch.sess_id);

FetchTask RefreshFetch = new FetchTask();

fetch.page++;
RefreshFetch.page = fetch.page++;
RefreshFetch.Selectedmonth = fetch.Selectedmonth;
RefreshFetch.Selectedyear = fetch.Selectedyear;
RefreshFetch.sess_id = fetch.sess_id;
RefreshFetch.ll = fetch.ll;

RefreshFetch.execute();

}

}


});

}
};


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}



public class FetchTask extends AsyncTask<Void, Void, JSONArray> {

public JSONArray result_arr;
public String result_str,email,password,test;
public int Selectedyear;
public int Selectedmonth;
public int page;
public String sess_id;
public ListView ll;
public ProgressDialog pd;
public ArrayAdapter<String> adapter;


@Override

protected JSONArray doInBackground(Void... params) {
try {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("MY SITE URL ....");

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);



nameValuePairs.add(new BasicNameValuePair("qw", "das"));
nameValuePairs.add(new BasicNameValuePair("debug", "1"));
nameValuePairs.add(new BasicNameValuePair("t", "0"));
nameValuePairs.add(new BasicNameValuePair("m", Integer.toString(this.Selectedmonth)));
nameValuePairs.add(new BasicNameValuePair("y", Integer.toString(this.Selectedyear)));
nameValuePairs.add(new BasicNameValuePair("st", Integer.toString(this.page)));

nameValuePairs.add(new BasicNameValuePair("sess_id", this.sess_id));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine());
String line = "0";
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
reader.close();
String result11 = sb.toString();

this.result_str = result11;
// parsing data
JSONArray arr = new JSONArray(result11);





return new JSONArray(result11);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}



@Override
protected void onPreExecute() {

}


My logs



03-05 13:24:43.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 49K, 7% free 3326K/3540K, paused 33ms, total 35ms
03-05 13:24:43.629: D/gralloc_goldfish(2052): Emulator without GPU emulation detected.
03-05 13:24:50.349: D/dalvikvm(2052): GC_FOR_ALLOC freed 151K, 8% free 3690K/4004K, paused 28ms, total 36ms
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): KeyEvent: ACTION_UP but key was not down.
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): in android.widget.EditText{b1e53a20 VFED..CL .F....I. 179,489-589,548 #7f090004 app:id/password}
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): 0: sent at 11916532000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=11916532, downTime=11916440, deviceId=0, source=0x101 }
03-05 13:24:55.809: D/dalvikvm(2052): GC_FOR_ALLOC freed 417K, 14% free 3788K/4368K, paused 31ms, total 31ms
03-05 13:24:56.509: D/dalvikvm(2052): GC_FOR_ALLOC freed 89K, 12% free 3877K/4368K, paused 39ms, total 42ms
03-05 13:24:56.549: D/dalvikvm(2052): GC_FOR_ALLOC freed 28K, 12% free 3947K/4468K, paused 39ms, total 40ms
03-05 13:24:56.599: I/dalvikvm-heap(2052): Grow heap (frag case) to 5.087MB for 1127536-byte allocation
03-05 13:24:56.649: D/dalvikvm(2052): GC_FOR_ALLOC freed <1K, 10% free 5048K/5572K, paused 48ms, total 48ms
03-05 13:25:14.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 504K, 12% free 5273K/5940K, paused 56ms, total 58ms
03-05 13:25:15.319: I/Choreographer(2052): Skipped 125 frames! The application may be doing too much work on its main thread.
03-05 13:25:15.809: I/Choreographer(2052): Skipped 49 frames! The application may be doing too much work on its main thread.
03-05 13:25:16.209: I/Choreographer(2052): Skipped 34 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.249: I/Choreographer(2052): Skipped 87 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.599: I/Choreographer(2052): Skipped 35 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.239: I/Choreographer(2052): Skipped 37 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.659: I/Choreographer(2052): Skipped 42 frames! The application may be doing too much work on its main thread.
03-05 13:25:23.629: I/Choreographer(2052): Skipped 98 frames! The application may be doing too much work on its main thread.
03-05 13:25:24.819: D/AndroidRuntime(2052): Shutting down VM
03-05 13:25:24.819: W/dalvikvm(2052): threadid=1: thread exiting with uncaught exception (group=0xb1aefba8)
03-05 13:25:24.919: E/AndroidRuntime(2052): FATAL EXCEPTION: main
03-05 13:25:24.919: E/AndroidRuntime(2052): Process: com.example.earchive, PID: 2052
03-05 13:25:24.919: E/AndroidRuntime(2052): java.lang.NullPointerException
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:291)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:1)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Handler.dispatchMessage(Handler.java:102)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Looper.loop(Looper.java:136)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invoke(Method.java:515)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-05 13:25:24.919: E/AndroidRuntime(2052): at dalvik.system.NativeStart.main(Native Method)
03-05 13:25:26.259: D/dalvikvm(2052): GC_FOR_ALLOC freed 385K, 9% free 5692K/6240K, paused 145ms, total 145ms


On post execute method



protected void onPostExecute(JSONArray result)
{
if (result != null)
{
List<String> subjects = new ArrayList<String>();
List<String> emails = new ArrayList<String>();

for(int i = 0; i < result.length(); i++)
{
try
{
JSONObject json_data = result.getJSONObject(i);
emails.add(json_data.getString("mittente"));
subjects.add(json_data.getString("oggetto"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
if(this.page == 0)
{
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
else
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}
}
else
{
System.out.println("Messages not found");

}
this.pd.dismiss();
}


}










share|improve this question




















  • 2




    Post logcat output as well.
    – MysticMagicϡ
    Mar 5 '14 at 18:19










  • i'v done it check it please
    – user3323180
    Mar 5 '14 at 18:27










  • I tried to salvage the introductory paragraph, but it was so hard to understand that I may have made a mistake. I apologize if my interpretation was poor. Can you please narrow down the code to only the portions that are relevant? You shouldn't post your entire program on Stack and expect us to look through all of it.
    – Rainbolt
    Mar 5 '14 at 18:27






  • 2




    NullPointerException on line 291. That's what is causing it to crash. Don't listen to John, more code is better.
    – Spidy
    Mar 5 '14 at 18:29












  • i have done it John
    – user3323180
    Mar 5 '14 at 18:32














0












0








0







My logic is as follows.
First, I get some data from the server. Then, I manipulate the data. Next, I put the data into a ListView. If the user scrolls to the bottom of this view, I want to refresh the view. I copy the properties from my Async object to a new object. At this point I see "unfortunately has stopped".



Here my code of activity class



    DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {


@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH,monthOfYear);

this.Syear = calendar.get(Calendar.YEAR);
this.Smonth = calendar.get(Calendar.MONTH);
Smonth = Smonth + 1;
InboxActivity i = new InboxActivity();

String user_id = getIntent().getExtras().getString(LoginActivity.SESSION_ID);

final FetchTask fetch = new FetchTask();
fetch.Selectedmonth = this.Smonth;
fetch.Selectedyear = this.Syear;
fetch.page = 0;
fetch.sess_id = user_id;
ListView ll = (ListView)findViewById(R.id.mailList);
fetch.ll = ll;
fetch.execute();

ll.setOnScrollListener(new OnScrollListener(){



@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
{
if(firstVisibleItem+visibleItemCount==totalItemCount)
{

//System.out.println("HERE WILL BE MY SESSION ID!!!!w");
//System.out.println(fetch.sess_id);

FetchTask RefreshFetch = new FetchTask();

fetch.page++;
RefreshFetch.page = fetch.page++;
RefreshFetch.Selectedmonth = fetch.Selectedmonth;
RefreshFetch.Selectedyear = fetch.Selectedyear;
RefreshFetch.sess_id = fetch.sess_id;
RefreshFetch.ll = fetch.ll;

RefreshFetch.execute();

}

}


});

}
};


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}



public class FetchTask extends AsyncTask<Void, Void, JSONArray> {

public JSONArray result_arr;
public String result_str,email,password,test;
public int Selectedyear;
public int Selectedmonth;
public int page;
public String sess_id;
public ListView ll;
public ProgressDialog pd;
public ArrayAdapter<String> adapter;


@Override

protected JSONArray doInBackground(Void... params) {
try {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("MY SITE URL ....");

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);



nameValuePairs.add(new BasicNameValuePair("qw", "das"));
nameValuePairs.add(new BasicNameValuePair("debug", "1"));
nameValuePairs.add(new BasicNameValuePair("t", "0"));
nameValuePairs.add(new BasicNameValuePair("m", Integer.toString(this.Selectedmonth)));
nameValuePairs.add(new BasicNameValuePair("y", Integer.toString(this.Selectedyear)));
nameValuePairs.add(new BasicNameValuePair("st", Integer.toString(this.page)));

nameValuePairs.add(new BasicNameValuePair("sess_id", this.sess_id));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine());
String line = "0";
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
reader.close();
String result11 = sb.toString();

this.result_str = result11;
// parsing data
JSONArray arr = new JSONArray(result11);





return new JSONArray(result11);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}



@Override
protected void onPreExecute() {

}


My logs



03-05 13:24:43.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 49K, 7% free 3326K/3540K, paused 33ms, total 35ms
03-05 13:24:43.629: D/gralloc_goldfish(2052): Emulator without GPU emulation detected.
03-05 13:24:50.349: D/dalvikvm(2052): GC_FOR_ALLOC freed 151K, 8% free 3690K/4004K, paused 28ms, total 36ms
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): KeyEvent: ACTION_UP but key was not down.
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): in android.widget.EditText{b1e53a20 VFED..CL .F....I. 179,489-589,548 #7f090004 app:id/password}
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): 0: sent at 11916532000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=11916532, downTime=11916440, deviceId=0, source=0x101 }
03-05 13:24:55.809: D/dalvikvm(2052): GC_FOR_ALLOC freed 417K, 14% free 3788K/4368K, paused 31ms, total 31ms
03-05 13:24:56.509: D/dalvikvm(2052): GC_FOR_ALLOC freed 89K, 12% free 3877K/4368K, paused 39ms, total 42ms
03-05 13:24:56.549: D/dalvikvm(2052): GC_FOR_ALLOC freed 28K, 12% free 3947K/4468K, paused 39ms, total 40ms
03-05 13:24:56.599: I/dalvikvm-heap(2052): Grow heap (frag case) to 5.087MB for 1127536-byte allocation
03-05 13:24:56.649: D/dalvikvm(2052): GC_FOR_ALLOC freed <1K, 10% free 5048K/5572K, paused 48ms, total 48ms
03-05 13:25:14.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 504K, 12% free 5273K/5940K, paused 56ms, total 58ms
03-05 13:25:15.319: I/Choreographer(2052): Skipped 125 frames! The application may be doing too much work on its main thread.
03-05 13:25:15.809: I/Choreographer(2052): Skipped 49 frames! The application may be doing too much work on its main thread.
03-05 13:25:16.209: I/Choreographer(2052): Skipped 34 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.249: I/Choreographer(2052): Skipped 87 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.599: I/Choreographer(2052): Skipped 35 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.239: I/Choreographer(2052): Skipped 37 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.659: I/Choreographer(2052): Skipped 42 frames! The application may be doing too much work on its main thread.
03-05 13:25:23.629: I/Choreographer(2052): Skipped 98 frames! The application may be doing too much work on its main thread.
03-05 13:25:24.819: D/AndroidRuntime(2052): Shutting down VM
03-05 13:25:24.819: W/dalvikvm(2052): threadid=1: thread exiting with uncaught exception (group=0xb1aefba8)
03-05 13:25:24.919: E/AndroidRuntime(2052): FATAL EXCEPTION: main
03-05 13:25:24.919: E/AndroidRuntime(2052): Process: com.example.earchive, PID: 2052
03-05 13:25:24.919: E/AndroidRuntime(2052): java.lang.NullPointerException
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:291)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:1)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Handler.dispatchMessage(Handler.java:102)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Looper.loop(Looper.java:136)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invoke(Method.java:515)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-05 13:25:24.919: E/AndroidRuntime(2052): at dalvik.system.NativeStart.main(Native Method)
03-05 13:25:26.259: D/dalvikvm(2052): GC_FOR_ALLOC freed 385K, 9% free 5692K/6240K, paused 145ms, total 145ms


On post execute method



protected void onPostExecute(JSONArray result)
{
if (result != null)
{
List<String> subjects = new ArrayList<String>();
List<String> emails = new ArrayList<String>();

for(int i = 0; i < result.length(); i++)
{
try
{
JSONObject json_data = result.getJSONObject(i);
emails.add(json_data.getString("mittente"));
subjects.add(json_data.getString("oggetto"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
if(this.page == 0)
{
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
else
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}
}
else
{
System.out.println("Messages not found");

}
this.pd.dismiss();
}


}










share|improve this question















My logic is as follows.
First, I get some data from the server. Then, I manipulate the data. Next, I put the data into a ListView. If the user scrolls to the bottom of this view, I want to refresh the view. I copy the properties from my Async object to a new object. At this point I see "unfortunately has stopped".



Here my code of activity class



    DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {


@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH,monthOfYear);

this.Syear = calendar.get(Calendar.YEAR);
this.Smonth = calendar.get(Calendar.MONTH);
Smonth = Smonth + 1;
InboxActivity i = new InboxActivity();

String user_id = getIntent().getExtras().getString(LoginActivity.SESSION_ID);

final FetchTask fetch = new FetchTask();
fetch.Selectedmonth = this.Smonth;
fetch.Selectedyear = this.Syear;
fetch.page = 0;
fetch.sess_id = user_id;
ListView ll = (ListView)findViewById(R.id.mailList);
fetch.ll = ll;
fetch.execute();

ll.setOnScrollListener(new OnScrollListener(){



@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
{
if(firstVisibleItem+visibleItemCount==totalItemCount)
{

//System.out.println("HERE WILL BE MY SESSION ID!!!!w");
//System.out.println(fetch.sess_id);

FetchTask RefreshFetch = new FetchTask();

fetch.page++;
RefreshFetch.page = fetch.page++;
RefreshFetch.Selectedmonth = fetch.Selectedmonth;
RefreshFetch.Selectedyear = fetch.Selectedyear;
RefreshFetch.sess_id = fetch.sess_id;
RefreshFetch.ll = fetch.ll;

RefreshFetch.execute();

}

}


});

}
};


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}



public class FetchTask extends AsyncTask<Void, Void, JSONArray> {

public JSONArray result_arr;
public String result_str,email,password,test;
public int Selectedyear;
public int Selectedmonth;
public int page;
public String sess_id;
public ListView ll;
public ProgressDialog pd;
public ArrayAdapter<String> adapter;


@Override

protected JSONArray doInBackground(Void... params) {
try {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("MY SITE URL ....");

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);



nameValuePairs.add(new BasicNameValuePair("qw", "das"));
nameValuePairs.add(new BasicNameValuePair("debug", "1"));
nameValuePairs.add(new BasicNameValuePair("t", "0"));
nameValuePairs.add(new BasicNameValuePair("m", Integer.toString(this.Selectedmonth)));
nameValuePairs.add(new BasicNameValuePair("y", Integer.toString(this.Selectedyear)));
nameValuePairs.add(new BasicNameValuePair("st", Integer.toString(this.page)));

nameValuePairs.add(new BasicNameValuePair("sess_id", this.sess_id));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine());
String line = "0";
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
reader.close();
String result11 = sb.toString();

this.result_str = result11;
// parsing data
JSONArray arr = new JSONArray(result11);





return new JSONArray(result11);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}



@Override
protected void onPreExecute() {

}


My logs



03-05 13:24:43.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 49K, 7% free 3326K/3540K, paused 33ms, total 35ms
03-05 13:24:43.629: D/gralloc_goldfish(2052): Emulator without GPU emulation detected.
03-05 13:24:50.349: D/dalvikvm(2052): GC_FOR_ALLOC freed 151K, 8% free 3690K/4004K, paused 28ms, total 36ms
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): KeyEvent: ACTION_UP but key was not down.
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): in android.widget.EditText{b1e53a20 VFED..CL .F....I. 179,489-589,548 #7f090004 app:id/password}
03-05 13:24:50.349: D/InputEventConsistencyVerifier(2052): 0: sent at 11916532000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=11916532, downTime=11916440, deviceId=0, source=0x101 }
03-05 13:24:55.809: D/dalvikvm(2052): GC_FOR_ALLOC freed 417K, 14% free 3788K/4368K, paused 31ms, total 31ms
03-05 13:24:56.509: D/dalvikvm(2052): GC_FOR_ALLOC freed 89K, 12% free 3877K/4368K, paused 39ms, total 42ms
03-05 13:24:56.549: D/dalvikvm(2052): GC_FOR_ALLOC freed 28K, 12% free 3947K/4468K, paused 39ms, total 40ms
03-05 13:24:56.599: I/dalvikvm-heap(2052): Grow heap (frag case) to 5.087MB for 1127536-byte allocation
03-05 13:24:56.649: D/dalvikvm(2052): GC_FOR_ALLOC freed <1K, 10% free 5048K/5572K, paused 48ms, total 48ms
03-05 13:25:14.239: D/dalvikvm(2052): GC_FOR_ALLOC freed 504K, 12% free 5273K/5940K, paused 56ms, total 58ms
03-05 13:25:15.319: I/Choreographer(2052): Skipped 125 frames! The application may be doing too much work on its main thread.
03-05 13:25:15.809: I/Choreographer(2052): Skipped 49 frames! The application may be doing too much work on its main thread.
03-05 13:25:16.209: I/Choreographer(2052): Skipped 34 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.249: I/Choreographer(2052): Skipped 87 frames! The application may be doing too much work on its main thread.
03-05 13:25:17.599: I/Choreographer(2052): Skipped 35 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.239: I/Choreographer(2052): Skipped 37 frames! The application may be doing too much work on its main thread.
03-05 13:25:22.659: I/Choreographer(2052): Skipped 42 frames! The application may be doing too much work on its main thread.
03-05 13:25:23.629: I/Choreographer(2052): Skipped 98 frames! The application may be doing too much work on its main thread.
03-05 13:25:24.819: D/AndroidRuntime(2052): Shutting down VM
03-05 13:25:24.819: W/dalvikvm(2052): threadid=1: thread exiting with uncaught exception (group=0xb1aefba8)
03-05 13:25:24.919: E/AndroidRuntime(2052): FATAL EXCEPTION: main
03-05 13:25:24.919: E/AndroidRuntime(2052): Process: com.example.earchive, PID: 2052
03-05 13:25:24.919: E/AndroidRuntime(2052): java.lang.NullPointerException
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:291)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.example.earchive.InboxActivity$FetchTask.onPostExecute(InboxActivity.java:1)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Handler.dispatchMessage(Handler.java:102)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.os.Looper.loop(Looper.java:136)
03-05 13:25:24.919: E/AndroidRuntime(2052): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 13:25:24.919: E/AndroidRuntime(2052): at java.lang.reflect.Method.invoke(Method.java:515)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-05 13:25:24.919: E/AndroidRuntime(2052): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-05 13:25:24.919: E/AndroidRuntime(2052): at dalvik.system.NativeStart.main(Native Method)
03-05 13:25:26.259: D/dalvikvm(2052): GC_FOR_ALLOC freed 385K, 9% free 5692K/6240K, paused 145ms, total 145ms


On post execute method



protected void onPostExecute(JSONArray result)
{
if (result != null)
{
List<String> subjects = new ArrayList<String>();
List<String> emails = new ArrayList<String>();

for(int i = 0; i < result.length(); i++)
{
try
{
JSONObject json_data = result.getJSONObject(i);
emails.add(json_data.getString("mittente"));
subjects.add(json_data.getString("oggetto"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
if(this.page == 0)
{
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
else
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}
}
else
{
System.out.println("Messages not found");

}
this.pd.dismiss();
}


}







java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 5:23









Cœur

17.4k9102143




17.4k9102143










asked Mar 5 '14 at 18:17









user3323180

2817




2817








  • 2




    Post logcat output as well.
    – MysticMagicϡ
    Mar 5 '14 at 18:19










  • i'v done it check it please
    – user3323180
    Mar 5 '14 at 18:27










  • I tried to salvage the introductory paragraph, but it was so hard to understand that I may have made a mistake. I apologize if my interpretation was poor. Can you please narrow down the code to only the portions that are relevant? You shouldn't post your entire program on Stack and expect us to look through all of it.
    – Rainbolt
    Mar 5 '14 at 18:27






  • 2




    NullPointerException on line 291. That's what is causing it to crash. Don't listen to John, more code is better.
    – Spidy
    Mar 5 '14 at 18:29












  • i have done it John
    – user3323180
    Mar 5 '14 at 18:32














  • 2




    Post logcat output as well.
    – MysticMagicϡ
    Mar 5 '14 at 18:19










  • i'v done it check it please
    – user3323180
    Mar 5 '14 at 18:27










  • I tried to salvage the introductory paragraph, but it was so hard to understand that I may have made a mistake. I apologize if my interpretation was poor. Can you please narrow down the code to only the portions that are relevant? You shouldn't post your entire program on Stack and expect us to look through all of it.
    – Rainbolt
    Mar 5 '14 at 18:27






  • 2




    NullPointerException on line 291. That's what is causing it to crash. Don't listen to John, more code is better.
    – Spidy
    Mar 5 '14 at 18:29












  • i have done it John
    – user3323180
    Mar 5 '14 at 18:32








2




2




Post logcat output as well.
– MysticMagicϡ
Mar 5 '14 at 18:19




Post logcat output as well.
– MysticMagicϡ
Mar 5 '14 at 18:19












i'v done it check it please
– user3323180
Mar 5 '14 at 18:27




i'v done it check it please
– user3323180
Mar 5 '14 at 18:27












I tried to salvage the introductory paragraph, but it was so hard to understand that I may have made a mistake. I apologize if my interpretation was poor. Can you please narrow down the code to only the portions that are relevant? You shouldn't post your entire program on Stack and expect us to look through all of it.
– Rainbolt
Mar 5 '14 at 18:27




I tried to salvage the introductory paragraph, but it was so hard to understand that I may have made a mistake. I apologize if my interpretation was poor. Can you please narrow down the code to only the portions that are relevant? You shouldn't post your entire program on Stack and expect us to look through all of it.
– Rainbolt
Mar 5 '14 at 18:27




2




2




NullPointerException on line 291. That's what is causing it to crash. Don't listen to John, more code is better.
– Spidy
Mar 5 '14 at 18:29






NullPointerException on line 291. That's what is causing it to crash. Don't listen to John, more code is better.
– Spidy
Mar 5 '14 at 18:29














i have done it John
– user3323180
Mar 5 '14 at 18:32




i have done it John
– user3323180
Mar 5 '14 at 18:32












1 Answer
1






active

oldest

votes


















0














Your this.adapter.add(json_data.getString("mittente")); is throwing a NullPointerException.



If page = 1, this.adapter is not initialized (page = 0) and is therefore NULL. If page 0 is guaranteed to be called before page 1, this would work, but I'm guessing it is not. Here's a fix if I understand your code correctly.



    if( this.adapter == null ) {
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
if(this.page != 0)
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}





share|improve this answer























  • It's work. Thanks!
    – user3323180
    Mar 5 '14 at 18:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22205913%2funfortunately-has-stopped-when-i-want-to-update-listview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your this.adapter.add(json_data.getString("mittente")); is throwing a NullPointerException.



If page = 1, this.adapter is not initialized (page = 0) and is therefore NULL. If page 0 is guaranteed to be called before page 1, this would work, but I'm guessing it is not. Here's a fix if I understand your code correctly.



    if( this.adapter == null ) {
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
if(this.page != 0)
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}





share|improve this answer























  • It's work. Thanks!
    – user3323180
    Mar 5 '14 at 18:46
















0














Your this.adapter.add(json_data.getString("mittente")); is throwing a NullPointerException.



If page = 1, this.adapter is not initialized (page = 0) and is therefore NULL. If page 0 is guaranteed to be called before page 1, this would work, but I'm guessing it is not. Here's a fix if I understand your code correctly.



    if( this.adapter == null ) {
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
if(this.page != 0)
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}





share|improve this answer























  • It's work. Thanks!
    – user3323180
    Mar 5 '14 at 18:46














0












0








0






Your this.adapter.add(json_data.getString("mittente")); is throwing a NullPointerException.



If page = 1, this.adapter is not initialized (page = 0) and is therefore NULL. If page 0 is guaranteed to be called before page 1, this would work, but I'm guessing it is not. Here's a fix if I understand your code correctly.



    if( this.adapter == null ) {
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
if(this.page != 0)
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}





share|improve this answer














Your this.adapter.add(json_data.getString("mittente")); is throwing a NullPointerException.



If page = 1, this.adapter is not initialized (page = 0) and is therefore NULL. If page 0 is guaranteed to be called before page 1, this would work, but I'm guessing it is not. Here's a fix if I understand your code correctly.



    if( this.adapter == null ) {
this.adapter = new ArrayAdapter<String>(
InboxActivity.this,
R.layout.da_item,
emails
);
this.ll.setAdapter(this.adapter);
}
if(this.page != 0)
{
for(int i = 0; i < result.length(); i++)
{
JSONObject json_data;
try
{
json_data = result.getJSONObject(i);
this.adapter.add(json_data.getString("mittente"));
}
catch (JSONException e)
{
e.printStackTrace();
}

}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 7:14









Alireza Noorali

1,367532




1,367532










answered Mar 5 '14 at 18:43









Spidy

26.7k145174




26.7k145174












  • It's work. Thanks!
    – user3323180
    Mar 5 '14 at 18:46


















  • It's work. Thanks!
    – user3323180
    Mar 5 '14 at 18:46
















It's work. Thanks!
– user3323180
Mar 5 '14 at 18:46




It's work. Thanks!
– user3323180
Mar 5 '14 at 18:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22205913%2funfortunately-has-stopped-when-i-want-to-update-listview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values