There are 2 Classes and 1 Interface: Class 1 = LoginPage, Class 2 = SyncData and Interface = AsyncTaskCompleteListener.
Class 1 uses Class 2 to sync information with the server. After Class 2 posts the result information in the onPostExecute method, the Interface callback method will be used to send the result information to Class 1. When I try to use the callback method, I get to see the following error:
04-12 11:06:43.715: W/dalvikvm(24941): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
04-12 11:06:43.720: E/AndroidRuntime(24941): FATAL EXCEPTION: main
04-12 11:06:43.720: E/AndroidRuntime(24941): java.lang.NullPointerException
04-12 11:06:43.720: E/AndroidRuntime(24941): at com.on_d_mand.live_evenementen.SyncData.onPostExecute(SyncData.java:101)
04-12 11:06:43.720: E/AndroidRuntime(24941): at com.on_d_mand.live_evenementen.SyncData.onPostExecute(SyncData.java:1)
04-12 11:06:43.720: E/AndroidRuntime(24941): at android.os.AsyncTask.finish(AsyncTask.java:417)
04-12 11:06:43.720: E/AndroidRuntime(24941): at android.os.AsyncTask.access$300(AsyncTask.java:127)
04-12 11:06:43.720: E/AndroidRuntime(24941): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
04-12 11:06:43.720: E/AndroidRuntime(24941): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 11:06:43.720: E/AndroidRuntime(24941): at android.os.Looper.loop(Looper.java:130)
04-12 11:06:43.720: E/AndroidRuntime(24941): at android.app.ActivityThread.main(ActivityThread.java:3691)
04-12 11:06:43.720: E/AndroidRuntime(24941): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 11:06:43.720: E/AndroidRuntime(24941): at java.lang.reflect.Method.invoke(Method.java:507)
04-12 11:06:43.720: E/AndroidRuntime(24941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
04-12 11:06:43.720: E/AndroidRuntime(24941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
04-12 11:06:43.720: E/AndroidRuntime(24941): at dalvik.system.NativeStart.main(Native Method)
Class 1 onTaskComplete method sample:
public void onTaskComplete(String result) {
//perform action after receiving the information
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
}
Class 2 onPostExecute method sample:
public void onPostExecute(String RESULT) {
if(dialog.isShowing()){
dialog.dismiss();
}
callback.onTaskComplete(RESULT);
}
Class 3:
package com.on_d_mand.live_evenementen;
public interface AsyncTaskCompleteListener<T> {
public void onTaskComplete(T result);
}
Does anyone knows what I'm doing wrong here? I hope it's not too complicated with the Classes and the Interface.
Edit
The solution for this problem was by initialising the callback object in the Class 2 contructor.