Reputation:
I downloaded a database from the internet and i'm trying to build my app on top of it. It's tested and it works. The problems begin when I try to open a new activity
I have a button called "New" on my main layout which is supposed to open a new window in my app (just open a new activity for now), but it crashes immediately on call. My current activity is DatabaseExampleActivity
(my main) and I want the new one to be NewAssignmentActivity
.
Here are the relevant code sections:
//the function that is called when "new" button is pressed
public void newAssignment(View view) {
Intent i = new Intent(DatabaseExampleActivity.this, NewAssignmentActivity.class);
startActivity(i);
}
//The manifest
<activity
android:name=".DatabaseExampleActivity"
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=".NewAssignmentActivity"
android:label="@string/title_activity_new_assignment" >
</activity>
//the new activity code
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class NewAssignmentActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_newassignment);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.new_assignment, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
consol writes in red : ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.anotherandroidblog.tools.database/.DatabaseExampleActivity }
ActivityManager: Warning: Activity not started, its current task has been brought to the front
The logCat also gives tons of errors too:
07-28 18:29:39.792: E/ERROR(5847): java.lang.NullPointerException
07-28 18:29:39.792: W/System.err(5847): java.lang.NullPointerException
07-28 18:29:39.792: W/System.err(5847): at com.anotherandroidblog.tools.database.DatabaseExampleActivity.addButtonListeners(DatabaseExampleActivity.java:104)
07-28 18:29:39.792: W/System.err(5847): at com.anotherandroidblog.tools.database.DatabaseExampleActivity.onCreate(DatabaseExampleActivity.java:51)
07-28 18:29:39.792: W/System.err(5847): at android.app.Activity.performCreate(Activity.java:5206)
07-28 18:29:39.792: W/System.err(5847): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-28 18:29:39.792: W/System.err(5847): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
07-28 18:29:39.792: W/System.err(5847): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
07-28 18:29:39.792: W/System.err(5847): at android.app.ActivityThread.access$700(ActivityThread.java:140)
07-28 18:29:39.792: W/System.err(5847): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
07-28 18:29:39.792: W/System.err(5847): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 18:29:39.792: W/System.err(5847): at android.os.Looper.loop(Looper.java:137)
07-28 18:29:39.792: W/System.err(5847): at android.app.ActivityThread.main(ActivityThread.java:4921)
07-28 18:29:39.792: W/System.err(5847): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 18:29:39.792: W/System.err(5847): at java.lang.reflect.Method.invoke(Method.java:511)
07-28 18:29:39.792: W/System.err(5847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-28 18:29:39.792: W/System.err(5847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-28 18:29:39.792: W/System.err(5847): at dalvik.system.NativeStart.main(Native Method)
07-28 18:29:59.301: I/brcm-gr(5847): [gralloc_lock]: new usage 0x933
07-28 18:29:59.301: D/AndroidRuntime(5847): Shutting down VM
07-28 18:29:59.301: W/dalvikvm(5847): threadid=1: thread exiting with uncaught exception (group=0x41bcf2a0)
07-28 18:29:59.311: E/AndroidRuntime(5847): FATAL EXCEPTION: main
07-28 18:29:59.311: E/AndroidRuntime(5847): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anotherandroidblog.tools.database/com.anotherandroidblog.tools.database.NewAssignmentActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.ActivityThread.access$700(ActivityThread.java:140)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.os.Looper.loop(Looper.java:137)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.ActivityThread.main(ActivityThread.java:4921)
07-28 18:29:59.311: E/AndroidRuntime(5847): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 18:29:59.311: E/AndroidRuntime(5847): at java.lang.reflect.Method.invoke(Method.java:511)
07-28 18:29:59.311: E/AndroidRuntime(5847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-28 18:29:59.311: E/AndroidRuntime(5847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-28 18:29:59.311: E/AndroidRuntime(5847): at dalvik.system.NativeStart.main(Native Method)
07-28 18:29:59.311: E/AndroidRuntime(5847): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
07-28 18:29:59.311: E/AndroidRuntime(5847): at com.anotherandroidblog.tools.database.NewAssignmentActivity.onCreate(NewAssignmentActivity.java:12)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.Activity.performCreate(Activity.java:5206)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-28 18:29:59.311: E/AndroidRuntime(5847): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
Upvotes: 0
Views: 2855
Reputation: 5030
Check out the crash log:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
NewAssignmentActivity
extends ActionBarActivity
, not Activity
, so you have to use Theme.AppCompat
for it. Set activity or application theme in AndroidManifest to
android:theme="@style/Theme.AppCompat"
Upvotes: 3