Reputation: 4655
I'm new in Android app development and now trying to write a first app. Bit when I want to show another Activity, the app crashes with the following logs (taken from LogCat):
02-01 18:05:50.148: D/HomeScreen(24970): news_button clicked
02-01 18:05:50.203: D/dalvikvm(24970): newInstance failed: p0 i0 [0 a1
02-01 18:05:50.210: D/AndroidRuntime(24970): Shutting down VM
02-01 18:05:50.210: W/dalvikvm(24970): threadid=1: thread exiting with uncaught exception (group=0x40018578)
02-01 18:05:50.218: E/AndroidRuntime(24970): FATAL EXCEPTION: main
02-01 18:05:50.218: E/AndroidRuntime(24970): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{me.the_Seppi.freakhall/me.the_Seppi.freakhall.NewsScreen}: java.lang.InstantiationException: me.the_Seppi.freakhall.NewsScreen
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.os.Looper.loop(Looper.java:130)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-01 18:05:50.218: E/AndroidRuntime(24970): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 18:05:50.218: E/AndroidRuntime(24970): at java.lang.reflect.Method.invoke(Method.java:507)
02-01 18:05:50.218: E/AndroidRuntime(24970): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-01 18:05:50.218: E/AndroidRuntime(24970): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-01 18:05:50.218: E/AndroidRuntime(24970): at dalvik.system.NativeStart.main(Native Method)
02-01 18:05:50.218: E/AndroidRuntime(24970): Caused by: java.lang.InstantiationException: me.the_Seppi.freakhall.NewsScreen
02-01 18:05:50.218: E/AndroidRuntime(24970): at java.lang.Class.newInstanceImpl(Native Method)
02-01 18:05:50.218: E/AndroidRuntime(24970): at java.lang.Class.newInstance(Class.java:1409)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-01 18:05:50.218: E/AndroidRuntime(24970): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
02-01 18:05:50.218: E/AndroidRuntime(24970): ... 11 more
The code executed is:
//HomeScreen.java
//...
public void gotoNews (View view) {
Log.d(TAG, "news_button clicked");
Intent news = new Intent(this, NewsScreen.class);
startActivity(news);
}
//NewsScreen.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news_screen);
Log.d("NewsScreen", "created");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.update_text).setTitle(R.string.update_title).create().show();
Log.d("NewsScreen", "Started update");
}
I can't find the error in my code, for there is no line number in the log. Please help me.
Upvotes: 0
Views: 97
Reputation: 4655
Problem solved: Just re-created the activity NewsScreen and all it's ressources.
But the code and manifest entry is the same. => What was wrong?
Upvotes: 0
Reputation: 4655
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.the_Seppi.freakhall"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="me.the_Seppi.freakhall.HomeScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="me.the_Seppi.freakhall.NewsScreen"
android:label="@string/title_activity_news_screen" >
</activity>
</application>
</manifest>
NewsScreen.java:
public abstract class NewsScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news_screen);
Log.d("NewsScreen", "created");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.update_text).setTitle(R.string.update_title).create().show();
Log.d("NewsScreen", "Started update");
}
@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_news_screen, menu);
return true;
}
}
I hope this will help you to solve this problem.
Upvotes: 0
Reputation: 1045
You need to add Activity to manifest file to which you are redirecting ex.
<activity android:name="sanatan.engine.MainActivity" />
Upvotes: 0
Reputation: 2981
Did you add this NewScreen Activity to your manifest file? This the most common problem with crashing activities.
Upvotes: 1