Navigation Drawer Activity

Asked

Viewed 673 times

1

I’m having a problem in an application I’m developing in Android Studio, it has the option to insert a Activity (Navigation Drawer Activity) then I inserted it and put a button to call it.

The problem is that when I click the button the application closes. When I create an application of this type (Navigation Drawer Activity) it works perfectly but I am not able to call it in my project already created.

I named it after MenuActivity and I want to go from login to it by clicking the button.

The method you call Activity:

public void click_chamaMenu(View view){
    Intent i = new Intent(Login.this,MenuActivity.class);
    startActivity(i);
}

logcat Error:

02-04 15:10:52.814  21392-21392/com.example.celsoribeiro.titanapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.celsoribeiro.titanapp, PID: 21392
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.celsoribeiro.titanapp/com.example.celsoribeiro.titanapp.MenuActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
            at android.app.ActivityThread.access$800(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
            at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
            at com.example.celsoribeiro.titanapp.MenuActivity.onCreate(MenuActivity.java:37)
            at android.app.Activity.performCreate(Activity.java:5953)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
            at android.app.ActivityThread.access$800(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

----------
  • Which logcat to quit? Show code where the error occurs.

  • No error appears, build successfull but the application is terminated.

  • The fact that the application has no errors when compiling does not mean that it does not have them when executing. When terminating, a message is shown?

  • Navigation Drawer is not a Fragment? good if it is a Activity even then the problem may be that you did not insert in the manifest.xml. Or because of what I saw you didn’t create Listener. Yes you put the call in XML in the instruction onClick, check the java method name if it is the same in xml.

  • When you close the app, only the message appears: "The Titan App has stopped."

  • It is an Activity yes but it has the Navigationdrawerfragment class which is a fragment, but I have entered it in the manifest yes.

  • If message appears "The Titan App Has Stopped." then, if you are running the application in Android Studio, the error will be displayed in the logcat. Edit your question and place it there.

  • 1

    I think I got it right here , the line that says : You need to use a Theme.Appcompat Theme (or Descendant) with this Activity. We missed to put the theme of Activity in the manifest, so I put got what I wanted. Thanks to everyone who helped me.

Show 3 more comments

1 answer

1

The reason you are making a mistake in the compilation is precisely because you are working with a class that extends ActionBarActivity (Deprecated in new versions) instead of AppCompatActivity.

Error line:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.celsoribeiro.titanapp/com.example.celsoribeiro.titanapp.MenuActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.


Try to insert android:theme="@style/Theme.AppCompat" in his AndroidManifest.xml, and ensure that the style used is compatible with Appcompat.


A friend tip I give you is to use the Material Drawer instead of Android Studio’s Navigation Drawer, it’s much more sophisticated and usually takes less work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.