-2

My java code:

 Button equations = (Button) findViewById(R.id.algebrabutton);
    equations.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), 
             algebra_activity.class);
            startActivityForResult(myIntent, 0);
        }
    });


    Button word = (Button) findViewById(R.id.wordbutton);
    word.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view1) {
            Intent myIntent1 = new Intent(view1.getContext(), 
               word_activity.class);
            startActivityForResult(myIntent1, 0);
        }
    });

Error log :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lawrencej.mathappdeluxe/com.exampl‌​e.lawrencej.mathappd‌​eluxe.algebra_activi‌​ty}: 
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor.
Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead

When I click the word button, it works fine and displays a new screen. When I click the equations button, the app crashes. Am I doing something wrong?

Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
Larry Jing
  • 383
  • 1
  • 5
  • 26
  • 1
    Show your error Log. – KeLiuyue Oct 25 '17 at 01:19
  • Theres no error on android studio, the app just crashes on my phone so I dont know if there is an error log – Larry Jing Oct 25 '17 at 01:21
  • 2
    The error log is in Android Studio... https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – OneCricketeer Oct 25 '17 at 01:27
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lawrencej.mathappdeluxe/com.example.lawrencej.mathappdeluxe.algebra_activity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead. – Larry Jing Oct 25 '17 at 01:32
  • oh I see so apparently I just cant have a toolbar. Well this fixes my problem, thanks for pointing out where the error log is :) – Larry Jing Oct 25 '17 at 01:33
  • You can check my answer.@LarryJing – KeLiuyue Oct 25 '17 at 02:21
  • @KeLiuyue I don't need to add those, I added a toolbar by myself because I wanted the extra addon, but apparently I can't. It doesnt have a toolbar by default. Thanks anyways :) – Larry Jing Oct 25 '17 at 03:42
  • What is wrong with my questions? I am now question banned... instead of just downvoting can people tell me what is wrong – Larry Jing Oct 30 '17 at 03:33

1 Answers1

0

Use this in your styles code .

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

And in your manifest

<activity
    android:name=".algebra_activity"
    android:theme="@style/AppTheme.NoActionBar">
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42