I already tried this code in my activity ..
In my First Activity this is my code to pass data :
Intent intent = new Intent(getApplicationContext(), TeacherSideQuestion2.class);
Bundle bundle = new Bundle();
bundle.putInt("score", finalScore);
intent.putExtras(bundle);
startActivityForResult(intent,0);
and in my Second Activity , here's the code to retrieve my data .
public void onClick() {
Bundle bundle = getIntent().getExtras();
// int temp = extras.getInt("score", 0);
// int temp = i.getExtras().getInt("score", 0);
if (bundle != null) {
int temp = bundle.getInt("score", 0);
if (temp >= 1) {
Intent intent = new Intent(TeacherSideQuestion2.this,
CongratsEnglish.class);
startActivity(intent);
} else {
Intent intent1 = new Intent(TeacherSideQuestion2.this,
FailedEnglish.class);
startActivity(intent1);
}
}
}
but when I try to click the onClick event , my application will crash .
can anyone fix this ?
Thank you for your answers .
Here's the LogCat says :
12-20 03:51:38.973: E/AndroidRuntime(3051): FATAL EXCEPTION: main
12-20 03:51:38.973: E/AndroidRuntime(3051): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.os.Looper.loop(Looper.java:137)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-20 03:51:38.973: E/AndroidRuntime(3051): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 03:51:38.973: E/AndroidRuntime(3051): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 03:51:38.973: E/AndroidRuntime(3051): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-20 03:51:38.973: E/AndroidRuntime(3051): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-20 03:51:38.973: E/AndroidRuntime(3051): at dalvik.system.NativeStart.main(Native Method)
12-20 03:51:38.973: E/AndroidRuntime(3051): Caused by: java.lang.NullPointerException
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:379)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.LoadedApk.getClassLoader(LoadedApk.java:322)
12-20 03:51:38.973: E/AndroidRuntime(3051): at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
12-20 03:51:38.973: E/AndroidRuntime(3051): ... 11 more
12-20 03:51:40.223: E/Trace(3085): error opening trace file: No such file or directory (2)