i think problem lies in xml file . app works in emulator on real device crashes when tried open activity. below xml , logcat.i retrieving data firebase when open activity 1 crashes on phone works fine on emulator. design view below shows failed instantiate 1 or more classes.
android.content.res.resources$notfoundexception @ com.android.layoutlib.bridge.android.bridgecontext.obtainstyledattributes(bridgecontext.java:681) @ android.content.res.resources_theme_delegate.obtainstyledattributes(resources_theme_delegate.java:71) @ android.content.res.resources$theme.obtainstyledattributes(resources.java:1436) @ android.content.context.obtainstyledattributes(context.java:587) @ android.support.v7.widget.tinttypedarray.obtainstyledattributes(tinttypedarray.java:59) @ android.support.design.widget.collapsingtexthelper.setexpandedtextappearance(collapsingtexthelper.java:231) @ android.support.design.widget.collapsingtoolbarlayout.<init>(collapsingtoolbarlayout.java:197) @ android.support.design.widget.collapsingtoolbarlayout.<init>(collapsingtoolbarlayout.java:143) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ org.jetbrains.android.uipreview.viewloader.createnewinstance(viewloader.java:475) @ org.jetbrains.android.uipreview.viewloader.loadclass(viewloader.java:262) @ org.jetbrains.android.uipreview.viewloader.loadview(viewloader.java:220) @ com.android.tools.idea.rendering.layoutlibcallbackimpl.loadview(layoutlibcallbackimpl.java:186) @ android.view.bridgeinflater.loadcustomview(bridgeinflater.java:334) @ android.view.bridgeinflater.loadcustomview(bridgeinflater.java:345) @ android.view.bridgeinflater.createviewfromtag(bridgeinflater.java:245) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:727) @ android.view.layoutinflater.rinflate_original(layoutinflater.java:858) @ android.view.layoutinflater_delegate.rinflate(layoutinflater_delegate.java:70) @ android.view.layoutinflater.rinflate(layoutinflater.java:834) @ android.view.layoutinflater.rinflatechildren(layoutinflater.java:821) @ android.view.layoutinflater.rinflate_original(layoutinflater.java:861) @ android.view.layoutinflater_delegate.rinflate(layoutinflater_delegate.java:70) @ android.view.layoutinflater.rinflate(layoutinflater.java:834) @ android.view.layoutinflater.rinflatechildren(layoutinflater.java:821) @ android.view.layoutinflater.inflate(layoutinflater.java:518) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ com.android.layoutlib.bridge.impl.rendersessionimpl.inflate(rendersessionimpl.java:324) @ com.android.layoutlib.bridge.bridge.createsession(bridge.java:429) @ com.android.ide.common.rendering.layoutlibrary.createsession(layoutlibrary.java:368) @ com.android.tools.idea.rendering.rendertask$2.compute(rendertask.java:567) @ com.android.tools.idea.rendering.rendertask$2.compute(rendertask.java:549) @ com.intellij.openapi.application.impl.applicationimpl.runreadaction(applicationimpl.java:863) @ com.android.tools.idea.rendering.rendertask.createrendersession(rendertask.java:549) @ com.android.tools.idea.rendering.rendertask.lambda$inflate$1(rendertask.java:680) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745)
xml code
<?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" tools:context="com.food.sheenishere.stark.fooddetail" > <android.support.design.widget.appbarlayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/themeoverlay.appcompat.dark.actionbar" android:fitssystemwindows="true" > <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/collapsing" android:layout_width="match_parent" android:layout_height="350dp" android:fitssystemwindows="true" app:layout_scrollflags="scroll|exituntilcollapsed" app:contentscrim="#0e0d0e" app:expandedtitletextappearance="@android:color/transparent" > <imageview android:id="@+id/img_food" android:layout_width="match_parent" android:layout_height="match_parent" android:contentdescription="@null" android:scaletype="centercrop" app:layout_collapsemode="parallax" /> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:title="food name" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" app:popuptheme="@style/themeoverlay.appcompat.light" app:layout_collapsemode="parallax" tools:ignore="hardcodedtext"> </android.support.v7.widget.toolbar> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout> <android.support.design.widget.floatingactionbutton android:id="@+id/btncart" android:src="@drawable/ic_shopping_cart_black_24dp" android:backgroundtint="@android:color/white" android:layout_width="wrap_content" android:layout_height="wrap_content" app:elevation="6dp" app:pressedtranslationz="12dp" app:layout_anchor="@id/app_bar_layout" app:layout_anchorgravity="bottom|right|end" app:usecompatpadding="true" tools:ignore="unusedattribute,vectordrawablecompat" /> <android.support.v4.widget.nestedscrollview android:id="@+id/nestedscrollview" android:cliptopadding="false" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" > <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.cardview android:layout_width="match_parent" android:layout_height="wrap_content" app:cardelevation="5dp" app:cardusecompatpadding="true" > <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/food_name" android:layout_margintop="8dp" android:padding="12dp" android:text="food name" android:textcolor="@color/colorprimary" android:textsize="20sp" android:textstyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="hardcodedtext" /> <linearlayout android:id="@+id/layout_price" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <imageview android:src="@drawable/ic_attach_money_black_24dp" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" tools:ignore="contentdescription,vectordrawablecompat" /> <textview android:id="@+id/food_price" android:text="1000" android:textcolor="@color/colorprimary" android:textsize="18sp" android:textstyle="bold" android:layout_width="0dp" android:layout_weight="9" android:layout_height="wrap_content" tools:ignore="hardcodedtext" /> </linearlayout> <com.cepheuen.elegantnumberbutton.view.elegantnumberbutton android:layout_width="100dp" android:layout_height="30dp" android:id="@+id/number_button" android:layout_margintop="8dp" android:layout_marginleft="8dp" android:layout_marginbottom="18dp" app:textsize="8sp" app:backgroundcolor="#0e0d0e" app:initialnumber="1" app:finalnumber="20" tools:ignore="rtlhardcoded,smallsp"> </com.cepheuen.elegantnumberbutton.view.elegantnumberbutton> </linearlayout> </android.support.v7.widget.cardview> <android.support.v7.widget.cardview app:cardelevation="5dp" app:cardusecompatpadding="true" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/food_description" android:layout_margintop="12dp" android:linespacingmultiplier="1.5" android:padding="12dp" android:text="description" android:textcolor="@android:color/black" android:textsize="14sp" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="hardcodedtext" /> </android.support.v7.widget.cardview> </linearlayout> </android.support.v4.widget.nestedscrollview> </android.support.design.widget.coordinatorlayout>
fooddetail.java
package com.food.sheenishere.stark; import android.support.design.widget.collapsingtoolbarlayout; import android.support.design.widget.floatingactionbutton; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.widget.imageview; import android.widget.textview; import com.cepheuen.elegantnumberbutton.view.elegantnumberbutton; import com.food.sheenishere.stark.model.food; import com.google.firebase.database.datasnapshot; import com.google.firebase.database.databaseerror; import com.google.firebase.database.databasereference; import com.google.firebase.database.firebasedatabase; import com.google.firebase.database.valueeventlistener; import com.squareup.picasso.picasso; public class fooddetail extends appcompatactivity { textview food_name,food_price,food_description; imageview food_image; collapsingtoolbarlayout collapsingtoolbarlayout; floatingactionbutton btncart; elegantnumberbutton numberbutton; string foodid=""; firebasedatabase database; databasereference foods; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_food_detail); //firebase database=firebasedatabase.getinstance(); foods=database.getreference("foods"); //init view numberbutton=(elegantnumberbutton)findviewbyid(r.id.number_button); btncart=(floatingactionbutton)findviewbyid(r.id.btncart); food_description=(textview)findviewbyid(r.id.food_description); food_name= (textview)findviewbyid(r.id.food_name); food_price= (textview)findviewbyid(r.id.food_price); food_image=(imageview)findviewbyid(r.id.img_food); collapsingtoolbarlayout=(collapsingtoolbarlayout)findviewbyid(r.id.collapsing); collapsingtoolbarlayout.setexpandedtitletextappearance(r.style.expandedappbar); collapsingtoolbarlayout.setcollapsedtitletextappearance(r.style.collapsedappbar); //get food id intent if (getintent() !=null) foodid =getintent().getstringextra("foodid"); if (!foodid.isempty()) { getdetailfood(foodid); } } private void getdetailfood(string foodid) { foods.child(foodid).addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { food food =datasnapshot.getvalue(food.class); //set image picasso.with(getbasecontext()).load(food.getimage()) .into(food_image); food_price.settext(food.getprice()); food_name.settext(food.getname()); food_description.settext(food.getdescription()); } @override public void oncancelled(databaseerror databaseerror) { } }); } }
instead of
android:backgroundtint="@android:color/white"
write this
app:backgroundtint="@android:color/white"
Comments
Post a Comment