Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to instantiate activity ComponentInfo error (Checked Manifest)
    primarykey
    data
    text
    <p>Hey guys I was running my app in an emulator but I ran into an error that caused the application to crash whenever I selected a list item. The error log I got was:</p> <pre><code>06-07 17:41:50.150: E/AndroidRuntime(624): FATAL EXCEPTION: main 06-07 17:41:50.150: E/AndroidRuntime(624): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dapps.factpalooza/com.dapps.factpalooza.animal}: java.lang.NullPointerException 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.ActivityThread.access$600(ActivityThread.java:130) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.os.Handler.dispatchMessage(Handler.java:99) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.os.Looper.loop(Looper.java:137) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.ActivityThread.main(ActivityThread.java:4745) 06-07 17:41:50.150: E/AndroidRuntime(624): at java.lang.reflect.Method.invokeNative(Native Method) 06-07 17:41:50.150: E/AndroidRuntime(624): at java.lang.reflect.Method.invoke(Method.java:511) 06-07 17:41:50.150: E/AndroidRuntime(624): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 06-07 17:41:50.150: E/AndroidRuntime(624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 06-07 17:41:50.150: E/AndroidRuntime(624): at dalvik.system.NativeStart.main(Native Method) 06-07 17:41:50.150: E/AndroidRuntime(624): Caused by: java.lang.NullPointerException 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.Activity.findViewById(Activity.java:1825) 06-07 17:41:50.150: E/AndroidRuntime(624): at com.dapps.factpalooza.animal.&lt;init&gt;(animal.java:29) 06-07 17:41:50.150: E/AndroidRuntime(624): at java.lang.Class.newInstanceImpl(Native Method) 06-07 17:41:50.150: E/AndroidRuntime(624): at java.lang.Class.newInstance(Class.java:1319) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.Instrumentation.newActivity(Instrumentation.java:1053) 06-07 17:41:50.150: E/AndroidRuntime(624): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974) 06-07 17:41:50.150: E/AndroidRuntime(624): ... 11 more </code></pre> <p>I've looked up this problem and it seemed like it had something to do with my manifest and not declaring activities properly, but I haven't messed with my manifest since it was working properly before. Even after a double check my manifest looked fine. I have no idea what's causing this error and what's causing my app to crash. My manifest:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dapps.factpalooza" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:debuggable="true"&gt; &lt;activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"&gt; &lt;/activity&gt; &lt;activity android:name="com.dapps.factpalooza.StartMenu" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.dapps.factpalooza.animal" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;activity android:name="com.dapps.factpalooza.Food" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;activity android:name="com.dapps.factpalooza.World" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;activity android:name="com.dapps.factpalooza.Law" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;activity android:name="com.dapps.factpalooza.Random_facts" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>My code for the menu:</p> <pre><code>package com.dapps.factpalooza; import android.os.Bundle; import android.app.ListActivity; import android.content.Intent; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class StartMenu extends ListActivity { String menuItems[] = {"Animal Facts", "Food Facts", "World Facts","Random Facts","Crazy Laws"}; String classNames[] = {"animal","Food","World","Random_facts","Law"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter&lt;String&gt;(StartMenu.this, android.R.layout.simple_list_item_1, menuItems)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); String classSelect = classNames[position]; try{ Class select = Class.forName("com.dapps.factpalooza." + classSelect); Intent selection = new Intent(StartMenu.this, select); startActivity(selection); }catch(ClassNotFoundException e){ e.printStackTrace(); } } } </code></pre> <p>and the code from one of my pages from the list:</p> <pre><code>package com.dapps.factpalooza; import java.util.Random; import com.google.ads.AdRequest; import com.google.ads.AdView; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class animal extends Activity { Button Generate; TextView Fact; TextView factNum; String animal_facts[] = { "Fact1", "Fact2", "Fact3", "Fact4", "Fact5", "Fact6", }; int total_facts = 5; Random r = new Random(); int Choosen; AdView ad = (AdView) findViewById(R.id.ad); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Generate = (Button) findViewById(R.id.generate); Fact = (TextView) findViewById(R.id.fact_display); factNum = (TextView) findViewById(R.id.fact_number); Generate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub ad.loadAd(new AdRequest()); Choosen = r.nextInt(total_facts); Fact.setText(animal_facts[Choosen]); factNum.setText("Fact # "+ Choosen); } }); } } </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