Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't pass int value between two activities
    primarykey
    data
    text
    <p>I tried to pass values from my main activity to my finish activity but I always got error in my finish activity. I don't know what's wrong with my code.</p> <p>Here's my code from my Level1 class:</p> <p><strong>Note:</strong> the Chronometer is already defined at the top of my activity, before onCreate method.</p> <pre><code>private void showElapsedTime() { chrono.start(); long timeElapsed = SystemClock.elapsedRealtime() - chrono.getBase(); int hours = (int) (timeElapsed / 3600000); int minutes = (int) (timeElapsed - hours * 3600000) / 60000; int seconds = (int) (timeElapsed - hours * 3600000 - minutes * 60000) / 1000; int seco = seconds; Toast.makeText(this, "Elapsed milliseconds: " + seconds, Toast.LENGTH_SHORT).show(); Intent a = new Intent (this, Finish.class); Bundle b = new Bundle(); b.putInt("sec", seco); a.putExtras(b); } </code></pre> <p>and this one is my Finish.class code:</p> <pre><code>Set1 = (TextView) findViewById (R.id.time1); Bundle b = getIntent().getExtras(); Set1.setText("time: " + b.getInt("seco")); </code></pre> <p><strong>LOGCAT:</strong></p> <pre><code>08-20 11:37:49.345: E/AndroidRuntime(815): FATAL EXCEPTION: main 08-20 11:37:49.345: E/AndroidRuntime(815): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mathattack/com.example.mathattack.Finish}: java.lang.NullPointerException 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.os.Handler.dispatchMessage(Handler.java:99) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.os.Looper.loop(Looper.java:123) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.ActivityThread.main(ActivityThread.java:4627) 08-20 11:37:49.345: E/AndroidRuntime(815): at java.lang.reflect.Method.invokeNative(Native Method) 08-20 11:37:49.345: E/AndroidRuntime(815): at java.lang.reflect.Method.invoke(Method.java:521) 08-20 11:37:49.345: E/AndroidRuntime(815): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 08-20 11:37:49.345: E/AndroidRuntime(815): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 08-20 11:37:49.345: E/AndroidRuntime(815): at dalvik.system.NativeStart.main(Native Method) 08-20 11:37:49.345: E/AndroidRuntime(815): Caused by: java.lang.NullPointerException 08-20 11:37:49.345: E/AndroidRuntime(815): at com.example.mathattack.Finish.onCreate(Finish.java:33) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-20 11:37:49.345: E/AndroidRuntime(815): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 08-20 11:37:49.345: E/AndroidRuntime(815): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload