Saturday, May 4, 2013

[android help] Unable to instantiate activitiy Componentinfo


I know there are many other questions like this, but I read them all and can´t find an answer for my problem.



05-04 08:38:40.742: E/AndroidRuntime(18186): FATAL EXCEPTION: main
05-04 08:38:40.742: E/AndroidRuntime(18186): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.unserekinder/com.example.unserekinder.MainActivity}: java.lang.NullPointerException
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.os.Looper.loop(Looper.java:137)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-04 08:38:40.742: E/AndroidRuntime(18186): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 08:38:40.742: E/AndroidRuntime(18186): at java.lang.reflect.Method.invoke(Method.java:511)
05-04 08:38:40.742: E/AndroidRuntime(18186): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-04 08:38:40.742: E/AndroidRuntime(18186): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-04 08:38:40.742: E/AndroidRuntime(18186): at dalvik.system.NativeStart.main(Native Method)
05-04 08:38:40.742: E/AndroidRuntime(18186): Caused by: java.lang.NullPointerException
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.Activity.findViewById(Activity.java:1839)
05-04 08:38:40.742: E/AndroidRuntime(18186): at com.example.unserekinder.MainActivity.(MainActivity.java:34)
05-04 08:38:40.742: E/AndroidRuntime(18186): at java.lang.Class.newInstanceImpl(Native Method)
05-04 08:38:40.742: E/AndroidRuntime(18186): at java.lang.Class.newInstance(Class.java:1319)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-04 08:38:40.742: E/AndroidRuntime(18186): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)


Manifest.xml:




package="com.example.unserekinder"
android:versionCode="1"
android:versionName="1.0" >

android:minSdkVersion="8"
android:targetSdkVersion="17" />

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="com.example.unserekinder.MainActivity"
android:label="@string/app_name" >






android:name="com.example.unserekinder.NeuesKind"
android:label="@string/title_activity_neues_kind" >






How you can see, all my Activites are defined in my Manifest.xml. There are also no abstract classes. Can´t find the problem.


My MainActivity:



package com.example.unserekinder;

...

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview_fuellen();

Button b = (Button) findViewById(R.id.btNeuesKind);
b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, NeuesKind.class);
startActivity(i);

}
});
}
DBHelper db = new DBHelper(this);
ListView lv = (ListView) findViewById(R.id.lvKinder);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

public void listview_fuellen(){
Cursor c = db.select();
int count = c.getCount();
String values[] = new String[count+1];
int i = 0;

while(c.moveToNext())
{
values[i]= c.getString(c.getColumnIndex("name"));
i++;
}


ArrayAdapter adapter = new ArrayAdapter(getBaseContext(),
android.R.layout.activity_list_item, android.R.id.text1,values);

lv.setAdapter(adapter);
}
}


What else could be the problem?



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...