java - This Activity already has an action bar supplied by the window decor Error on Android Studio -


i'm trying launch new activity main one. every time execute get,

unfortunately, application has stopped. 

i´ve been going through similar questions still can't solve problem.

here's manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.usuario.myapplication"> <application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:supportsrtl="true"     android:theme="@style/apptheme">      <activity android:name=".mainactivity">     <intent-filter>         <action android:name="android.intent.action.main" />          <category android:name="android.intent.category.launcher" />     </intent-filter> </activity>     <activity         android:name=".secondactivity">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.default" />         </intent-filter>     </activity> </application> </manifest> 

java:

public class mainactivity extends appcompatactivity implements view.onclicklistener{      textview texto;     edittext edittext;     button boton;     button boton2;      private googleapiclient client;      @override     public void onclick(view v) {         switch (v.getid()) {             case (r.id.boton):                 string dato = edittext.gettext().tostring();                 toast.maketext(getapplicationcontext(), dato, toast.length_short).show();                 texto.settext(dato);                 break;             case (r.id.boton2):                 intent intent = new intent(mainactivity.this, secondactivity.class);                 startactivity(intent);                 break;         }     }       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         // attention: auto-generated implement app indexing api.         // see https://g.co/appindexing/androidstudio more information.         client = new googleapiclient.builder(this).addapi(appindex.api).build();          texto = (textview)findviewbyid(r.id.texto);         edittext = (edittext)findviewbyid(r.id.edittext);         boton = (button)findviewbyid(r.id.boton);         boton2 = (button)findviewbyid(r.id.boton2);         boton.setonclicklistener(this);         boton2.setonclicklistener(this);        }      @override     public void onstart() {         super.onstart();          // attention: auto-generated implement app indexing api.         // see https://g.co/appindexing/androidstudio more information.         client.connect();         action viewaction = action.newaction(                 action.type_view, // todo: choose action type.                 "main page", // todo: define title content shown.                 // todo: if have web page content matches app activity's content,                 // make sure auto-generated web page url correct.                 // otherwise, set url null.                 uri.parse("http://host/path"),                 // todo: make sure auto-generated app deep link uri correct.                 uri.parse("android-app://com.example.usuario.myapplication/http/host/path")         );         appindex.appindexapi.start(client, viewaction);     }      @override     public void onstop() {         super.onstop();          // attention: auto-generated implement app indexing api.         // see https://g.co/appindexing/androidstudio more information.         action viewaction = action.newaction(                 action.type_view, // todo: choose action type.                 "main page", // todo: define title content shown.                 // todo: if have web page content matches app activity's content,                 // make sure auto-generated web page url correct.                 // otherwise, set url null.                 uri.parse("http://host/path"),                 // todo: make sure auto-generated app deep link uri correct.                 uri.parse("android-app://com.example.usuario.myapplication/http/host/path")         );         appindex.appindexapi.end(client, viewaction);         client.disconnect();     } } 

xml:

 <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.example.usuario.myapplication.mainactivity">      <textview         android:id="@+id/texto"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="hello world!" />      <edittext         android:id="@+id/edittext"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:hint="ingresar dato" />      <button         android:id="@+id/boton"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="@string/boton" />      <button         android:id="@+id/boton2"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="new activity" />  </linearlayout> 

and here logcat:

01-24 14:27:42.042 8033-8033/com.example.usuario.myapplication e/androidruntime: fatal exception: main                   process: com.example.usuario.myapplication, pid: 8033                   java.lang.runtimeexception: unable start activity componentinfo{com.example.usuario.myapplication/com.example.usuario.myapplication.secondactivity}: java.lang.illegalstateexception: activity has action bar supplied window decor. not request window.feature_support_action_bar , set windowactionbar false in theme use toolbar instead.                       @ android.app.activitythread.performlaunchactivity(activitythread.java:2416)                       @ android.app.activitythread.handlelaunchactivity(activitythread.java:2476)                       @ android.app.activitythread.-wrap11(activitythread.java)                       @ android.app.activitythread$h.handlemessage(activitythread.java:1344)                       @ android.os.handler.dispatchmessage(handler.java:102)                       @ android.os.looper.loop(looper.java:148)                       @ android.app.activitythread.main(activitythread.java:5417)                       @ java.lang.reflect.method.invoke(native method)                       @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726)                       @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)                    caused by: java.lang.illegalstateexception: activity has action bar supplied window decor. not request window.feature_support_action_bar , set windowactionbar false in theme use toolbar instead.                       @ android.support.v7.app.appcompatdelegateimplv7.setsupportactionbar(appcompatdelegateimplv7.java:198)                       @ android.support.v7.app.appcompatactivity.setsupportactionbar(appcompatactivity.java:99)                       @ com.example.usuario.myapplication.secondactivity.oncreate(secondactivity.java:17)                       @ android.app.activity.performcreate(activity.java:6237)                       @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1107)                       @ android.app.activitythread.performlaunchactivity(activitythread.java:2369)                       @ android.app.activitythread.handlelaunchactivity(activitythread.java:2476)                        @ android.app.activitythread.-wrap11(activitythread.java)                        @ android.app.activitythread$h.handlemessage(activitythread.java:1344)                        @ android.os.handler.dispatchmessage(handler.java:102)                        @ android.os.looper.loop(looper.java:148)                        @ android.app.activitythread.main(activitythread.java:5417)                        @ java.lang.reflect.method.invoke(native method)                        @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726)                        @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)  

second activity:

package com.example.usuario.myapplication;  import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.view;  public class secondactivity extends appcompatactivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_second);     toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab);     fab.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             snackbar.make(view, "replace own action", snackbar.length_long)                     .setaction("action", null).show();         }     }); }  } 

as per logcat log; there confliction between implementation of manifest file , secondactivity class.

you got 2 solutions here implement either of them :

  1. you can remove complete 2 line "toolbar" implementation code.
  2. you may make change in manifest file below :

             android:theme="@style/apptheme.noactionbar" 

hope out.

cheers!


Comments