java - IllegalStateException when launching application after moved between computers -
tl;dr
these exact files work on 1 workstation, , not one.
what (error)
fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.example.erik.recipefriend2/com.example.erik.recipefriend2.mainactivity}: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity.
the error @ line 26, in case this:
setsupportactionbar(toolbar);
what have done topic states, have been moving android studio project stationary computer onto laptop. have been using git bitbucket able work on both computers. when pulled project , tried run it, got error message displayed above. when zipped project stationary computer , unpacked , launched on laptop, got same error. lastly, pasted indivudial files (class files, drawables , xml-files) newly created project, still error.
i running out of ideas. have line line checked classes on stationary computer , compared them lines on laptop, no avail.
i include classes , xmls think involved in matter.
styles.xml
<resources> <!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light.noactionbar"> <!-- customize theme here. --> <item name="colorprimary">@color/colorprimary</item> <item name="colorprimarydark">@color/colorprimarydark</item> <item name="android:actionoverflowbuttonstyle">@style/overflow</item> </style> <style name="themeoverlay.recipesapp" parent="theme.appcompat.noactionbar"> <item name="android:colorbackground">@color/colorgreen</item> <item name="android:textcolor">#ffffff</item> </style> <style name="overflow" parent="widget.appcompat.actionbutton.overflow"> <item name="android:src">@drawable/ic_menu_white_24dp</item> </style> </resources>
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.erik.recipefriend2"> <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" android:label="@string/app_name" android:theme="@style/apptheme.noactionbar"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:context="com.example.erik.recipefriend2.mainactivity"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/apptheme"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="?attr/colorprimary" app:popuptheme="@style/themeoverlay.recipesapp" /> </android.support.design.widget.appbarlayout> <include layout="@layout/content_main" /> <android.support.design.widget.floatingactionbutton android:id="@+id/addingredient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:layout_margin="16dp" app:backgroundtint="#91ff93" android:tint="#ffffff" android:onclick="gotoadd" android:scaletype="fitcenter" android:src="@android:drawable/ic_input_add" /> <android.support.design.widget.floatingactionbutton android:id="@+id/searchrecipe" android:layout_width="wrap_content" android:layout_height="wrap_content" app:backgroundtint="#91ff93" android:src="@android:drawable/ic_search_category_default" android:layout_margin="16dp" android:tint="#ffffff" android:scaletype="fitcenter" android:onclick="gotosearch" android:layout_gravity="bottom|left" /> </android.support.design.widget.coordinatorlayout>
mainactivity.java
package com.example.erik.recipefriend2; import android.graphics.color; 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.util.log; import android.view.menuinflater; import android.view.view; import android.view.menu; import java.lang.reflect.method; public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); toolbar.settitletextcolor(color.white); setsupportactionbar(toolbar); android.support.v7.app.actionbar actionbar = getsupportactionbar(); actionbar.setlogo(r.mipmap.ic_launcher); actionbar.setdisplayuselogoenabled(true); actionbar.setdisplayshowhomeenabled(true); floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.addingredient); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { snackbar.make(view, "replace own action", snackbar.length_long) .setaction("action", null).show(); } }); } @override public boolean oncreateoptionsmenu(menu menu){ menuinflater menuinflater = getmenuinflater(); menuinflater.inflate(r.menu.activity_main_actions, menu); return super.oncreateoptionsmenu(menu); } @override protected boolean onprepareoptionspanel(view view, menu menu) { if (menu != null) { if (menu.getclass().getsimplename().equals("menubuilder")) { try { method m = menu.getclass().getdeclaredmethod( "setoptionaliconsvisible", boolean.type); m.setaccessible(true); m.invoke(menu, true); } catch (exception e) { log.e(getclass().getsimplename(), "onmenuopened...unable set icons overflow menu", e); } } } return super.onprepareoptionspanel(view, menu); } public void gotoadd(view view){ } public void gotosearch(){ } }
what can problem be? also, if more files needed, happy display them well.
on you're activity define android:theme="@style/apptheme.noactionbar"
while don't define apptheme.noactionbar
anywhere in styles. it's confusing compiles, explain why there's error.
Comments
Post a Comment