Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid crash in onCreate
    primarykey
    data
    text
    <p>Whenever I run my app, the first time I run it from Eclipse it runs fine. But then if I close the app and reopen it it will crash on onCreate. Here is the LogCat:</p> <pre><code>10-10 02:50:00.665: E/AndroidRuntime(29564): FATAL EXCEPTION: main 10-10 02:50:00.665: E/AndroidRuntime(29564): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appuccino.unitconverter/com.appuccino.unitconverter.MainActivity}: java.lang.NullPointerException 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.ActivityThread.access$600(ActivityThread.java:140) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.os.Handler.dispatchMessage(Handler.java:99) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.os.Looper.loop(Looper.java:137) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.ActivityThread.main(ActivityThread.java:4898) 10-10 02:50:00.665: E/AndroidRuntime(29564): at java.lang.reflect.Method.invokeNative(Native Method) 10-10 02:50:00.665: E/AndroidRuntime(29564): at java.lang.reflect.Method.invoke(Method.java:511) 10-10 02:50:00.665: E/AndroidRuntime(29564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008) 10-10 02:50:00.665: E/AndroidRuntime(29564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 10-10 02:50:00.665: E/AndroidRuntime(29564): at dalvik.system.NativeStart.main(Native Method) 10-10 02:50:00.665: E/AndroidRuntime(29564): Caused by: java.lang.NullPointerException 10-10 02:50:00.665: E/AndroidRuntime(29564): at com.appuccino.unitconverter.MainActivity.onCreate(MainActivity.java:37) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.Activity.performCreate(Activity.java:5206) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 10-10 02:50:00.665: E/AndroidRuntime(29564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 10-10 02:50:00.665: E/AndroidRuntime(29564): ... 11 more </code></pre> <p>And the first part of my mainActivity:</p> <pre><code>public class MainActivity extends FragmentActivity implements OnItemSelectedListener { /** * The serialization (saved instance state) Bundle key representing the * current dropdown position. */ private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; private Spinner firstSpinner; private Spinner secondSpinner; final String[] mainCategoryChoices = {"Acceleration", "Angles", "Area", "Astronomical", "Clothing", "Computers and Electronics", "Cooking", "Date/Time", "Density", "Energy"}; final String[] subCategoryChoices = {"Acre", "Barn", "Bunder", "Hundred", "Jerib", "Kappland", "Labor", "Ping", "Rai", "Shed", "Sitio", "Square", "Square Mile", "Square Yard"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); //not necessary setContentView(R.layout.activity_main); ArrayAdapter&lt;String&gt; firstAdapter = new ArrayAdapter&lt;String&gt;( MainActivity.this, android.R.layout.simple_dropdown_item_1line, mainCategoryChoices); ArrayAdapter&lt;String&gt; secondAdapter = new ArrayAdapter&lt;String&gt;( MainActivity.this, android.R.layout.simple_dropdown_item_1line, subCategoryChoices); final ActionBar actionBar = getActionBar(); if(actionBar != null) { actionBar.setCustomView(R.layout.action_bar_custom); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowHomeEnabled(false); } firstSpinner = (Spinner) findViewById(R.id.firstSpinner); secondSpinner = (Spinner) findViewById(R.id.secondSpinner); firstSpinner.setAdapter(firstAdapter); secondSpinner.setAdapter(secondAdapter); firstSpinner.setOnItemSelectedListener(this); secondSpinner.setOnItemSelectedListener(this); } </code></pre> <p>Line 37 that the log info is pointing to goes to the line saying </p> <pre><code>final String[] subCategoryChoices = {"Acre", "Barn", "Bunder", "Hundred", "Jerib", "Kappland", "Labor", "Ping", "Rai", "Shed", "Sitio", "Square", "Square Mile", "Square Yard"}; </code></pre> <p>though when I click on it it goes to the line just above the onCreate(), what could be making it crash?</p>
    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.
 

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