I use loading before load completed listview
This code worked :
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listContent = (ListView) findViewById(R.id.listContent); adapter = new AdapterNote(G.tasks); listContent.setAdapter(adapter); Commands.readData(); adapter.notifyDataSetChanged(); } But after changing to the below code , application crashed and force closed :
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startDialog(); } ProgressDialog pd; private void startDialog() { pd = ProgressDialog.show(NoteActivity.this, "title", "loading"); new Thread(new Runnable() { @Override public void run() { final ListView listContent = (ListView) findViewById(R.id.listContent); adapter = new AdapterNote(G.tasks); listContent.setAdapter(adapter); Commands.readData(); adapter.notifyDataSetChanged(); handler.sendEmptyMessage(0); } }).start(); } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { pd.dismiss(); } }; In log cat these errors occurred :
03-08 00:27:09.734: E/AndroidRuntime(334): FATAL EXCEPTION: main 03-08 00:27:09.734: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NoteProject.download.app/com.NoteProject.download.app.NoteNoteProjectActivity}: java.lang.NullPointerException 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:99) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:4627) 03-08 00:27:09.734: E/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method) 03-08 00:27:09.734: E/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:521) 03-08 00:27:09.734: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 03-08 00:27:09.734: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 03-08 00:27:09.734: E/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method) 03-08 00:27:09.734: E/AndroidRuntime(334): Caused by: java.lang.NullPointerException 03-08 00:27:09.734: E/AndroidRuntime(334): at com.NoteProject.download.app.NoteNoteProjectActivity$2.onScroll(NoteNoteProjectActivity.java:79) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:675) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.widget.AbsListView.setOnScrollListener(AbsListView.java:664) 03-08 00:27:09.734: E/AndroidRuntime(334): at com.NoteProject.download.app.NoteNoteProjectActivity.onCreate(NoteNoteProjectActivity.java:69) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 03-08 00:27:09.734: E/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 03-08 00:27:09.734: E/AndroidRuntime(334): ... 11 more How to fix it ?
In commands.readdata() , return listview from web
Thx