Note that there are some explanatory texts on larger screens.

plurals
  1. POGet bundle values in Android
    primarykey
    data
    text
    <p>I'm still really confused why I'm having error getting values from the bundle of my main activity.</p> <p>So, here's my code snippet:</p> <p><strong>Level1.class</strong></p> <pre><code>Chronometer chrono; chrono = (Chronometer)findViewById(R.id.chronometer1); 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; Intent lvl1 = new Intent(getApplicationContext(), Finish.class); Bundle time1 = new Bundle(); time1.putInt("hour1", hours); time1.putInt("minutes1", minutes); time1.putInt("seconds1", seconds); lvl1.putExtras(time1); </code></pre> <p>and my <strong>Finish.class</strong>: (inside the onCreate method)</p> <pre><code>TextView Set1; Set1 = (TextView) findViewById (R.id.time1); Bundle time1 = getIntent().getExtras(); int hrs = time1.getInt("hour1"); int min = time1.getInt("minutes1"); int sec = time1.getInt("seconds1"); Set1.setText(hrs + ":" + min + ":" + sec); </code></pre> <p>Could anyone tell me why I'm having errors?</p> <p><strong>Note:</strong> ERROR in line 30, which is the <code>int hrs = time1.getInt("hour1");</code>.</p> <p>LOGCAT:</p> <pre><code>08-20 01:54:10.461: E/AndroidRuntime(950): FATAL EXCEPTION: main 08-20 01:54:10.461: E/AndroidRuntime(950): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mathattack/com.example.mathattack.Finish}: java.lang.NullPointerException 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.os.Handler.dispatchMessage(Handler.java:99) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.os.Looper.loop(Looper.java:123) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.ActivityThread.main(ActivityThread.java:4627) 08-20 01:54:10.461: E/AndroidRuntime(950): at java.lang.reflect.Method.invokeNative(Native Method) 08-20 01:54:10.461: E/AndroidRuntime(950): at java.lang.reflect.Method.invoke(Method.java:521) 08-20 01:54:10.461: E/AndroidRuntime(950): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 08-20 01:54:10.461: E/AndroidRuntime(950): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 08-20 01:54:10.461: E/AndroidRuntime(950): at dalvik.system.NativeStart.main(Native Method) 08-20 01:54:10.461: E/AndroidRuntime(950): Caused by: java.lang.NullPointerException 08-20 01:54:10.461: E/AndroidRuntime(950): at com.example.mathattack.Finish.onCreate(Finish.java:30) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-20 01:54:10.461: E/AndroidRuntime(950): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 08-20 01:54:10.461: E/AndroidRuntime(950): ... 11 more </code></pre>
    singulars
    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.
    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