Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Bundle - Start Activity and set a bundle to Null
    primarykey
    data
    text
    <p>Im trying to start an Activity, which includes Bundles. I'm trying to set this bundls to be null for now since nothing has yet been passed on to this activity.</p> <pre><code>public class DailyActivities extends Activity implements OnClickListener{ TextView scoreA int gotA; int counter_score; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); counter_score=0; int questions_1 = 26; initialize(); ///////PSEUDO CODE...this is where Im trying to say, if no bundled is passed, ////////then setText for scoreA to the int counter score, ////////so that the activity doesn't crash due to null pointer exception//// Bundle gotA = getIntent().getExtras(); if(gotA == null){ scoreA.setText(counter_score); }else if (gotA != null){ gotLetterA = gotA.getInt("key"); counter_score = gotLetterA; int percentage = (int)( gotLetterA * 100.0 / questions_1 + 0.5); scoreA.setText(percentage); } } </code></pre> <p>Currently activity crashes with the a android.resources not found error</p> <p>edit- added error log</p> <p>08-24 10:39:33.180: E/AndroidRuntime(21177): FATAL EXCEPTION: main 08-24 10:39:33.180: E/AndroidRuntime(21177): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.app/com.test.app.DailyActivities}: android.content.res.Resources$NotFoundException: String resource ID #0x0 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.ActivityThread.access$600(ActivityThread.java:130) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.os.Handler.dispatchMessage(Handler.java:99) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.os.Looper.loop(Looper.java:137) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.ActivityThread.main(ActivityThread.java:4745) 08-24 10:39:33.180: E/AndroidRuntime(21177): at java.lang.reflect.Method.invokeNative(Native Method) 08-24 10:39:33.180: E/AndroidRuntime(21177): at java.lang.reflect.Method.invoke(Method.java:511) 08-24 10:39:33.180: E/AndroidRuntime(21177): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 08-24 10:39:33.180: E/AndroidRuntime(21177): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 08-24 10:39:33.180: E/AndroidRuntime(21177): at dalvik.system.NativeStart.main(Native Method) 08-24 10:39:33.180: E/AndroidRuntime(21177): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.content.res.Resources.getText(Resources.java:229) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.widget.TextView.setText(TextView.java:3620) 08-24 10:39:33.180: E/AndroidRuntime(21177): at com.MovilTeacher_titan.app.DailyActivities.onCreate(DailyActivities.java:164) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.Activity.performCreate(Activity.java:5008) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 08-24 10:39:33.180: E/AndroidRuntime(21177): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)</p> <p>Soooooo here is the solution, I was being dense lol</p> <pre><code>Bundle gotA = getIntent().getExtras();{ if(gotA == null){ scoreA.setText("0%"); }else { myPkg = gotA.getInt("key"); counter_score = myPkg; int percentage = (int)( myPkg * 100.0 / questions_1 + 0.5); scoreA.setText(""+percentage); } } </code></pre>
    singulars
    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