java - Resources$NotFoundException -
so whenever run app, it'll instantly crash , give me following error:
no package identifier when getting value resource number 0x00000000 fatal exception: main process: com.example.wessel.weer, pid: 3095 android.content.res.resources$notfoundexception: resource id #0x0 @ android.content.res.resources.getvalue(resources.java:1351) @ android.content.res.resources.getdrawable(resources.java:804) @ android.content.res.resources.getdrawable(resources.java:771) @ com.example.wessel.weer.mainactivity.servicesuccess(mainactivity.java:52) @ com.example.wessel.weer.service.yahooweatherservice$1.onpostexecute(yahooweatherservice.java:91) @ com.example.wessel.weer.service.yahooweatherservice$1.onpostexecute(yahooweatherservice.java:40) @ android.os.asynctask.finish(asynctask.java:651) @ android.os.asynctask.-wrap1(asynctask.java) @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:668) @ 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)
is there way manually fix this? how import library?
edit: here's mainactivity:
package com.example.wessel.weer; import android.app.progressdialog; import android.graphics.drawable.drawable; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.widget.imageview; import android.widget.textview; import android.widget.toast; import com.example.wessel.weer.data.channel; import com.example.wessel.weer.data.item; import com.example.wessel.weer.service.weatherservicecallback; import com.example.wessel.weer.service.yahooweatherservice; public class mainactivity extends appcompatactivity implements weatherservicecallback { private imageview weathericonimageview; private textview temperaturetextview; private textview conditiontextview; private textview locationtextview; private yahooweatherservice service; private progressdialog dialog; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); weathericonimageview = (imageview)findviewbyid(r.id.weathericonimageview); temperaturetextview = (textview)findviewbyid(r.id.temperaturetextview); conditiontextview = (textview)findviewbyid(r.id.conditiontextview); locationtextview = (textview)findviewbyid(r.id.locationtextview); service = new yahooweatherservice(this); dialog = new progressdialog(this); dialog.setmessage("laden..."); dialog.show(); service.refreshweather("austin, tx"); } @override public void servicesuccess(channel channel) { dialog.hide(); item item = channel.getitem(); int resourceid = getresources().getidentifier("drawable/icon_" + item.getcondition().getcode(), null, getpackagename()); @suppresswarnings("deprecation") drawable weathericondrawable = getresources().getdrawable(resourceid); weathericonimageview.setimagedrawable(weathericondrawable); temperaturetextview.settext(item.getcondition().gettemperature()+ "\u00b0" +channel.getunits().gettemperature()); conditiontextview.settext(item.getcondition().getdescription()); //conditiontextview.settext(condition.getdescription()); locationtextview.settext(service.getlocation()); } @override public void servicefailure(exception exception) { dialog.hide(); toast.maketext(this, exception.getmessage(), toast.length_long).show(); } }
also here's activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout 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: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.wessel.weer.mainactivity"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/weathericonimageview" android:src="@drawable/cna" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="@string/temperature" android:id="@+id/temperaturetextview" android:layout_below="@+id/weathericonimageview" android:layout_centerhorizontal="true" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancesmall" android:text="@string/condition" android:id="@+id/conditiontextview" android:layout_below="@+id/temperaturetextview" android:layout_centerhorizontal="true" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/location" android:id="@+id/locationtextview" android:layout_below="@+id/conditiontextview" android:layout_centerhorizontal="true" /> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/yahoo_logo" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" /> </relativelayout>
hope i've included enough now.
you failing check return value of getidentifier()
int resourceid = getresources().getidentifier("drawable/icon_" + item.getcondition().getcode(), null, getpackagename());
the documentation of getidentifier() says
returns 0 if no such resource found. (0 not valid resource id.)
to figure out why no such resource being found, have evaluate , contemplate this:
"drawable/icon_" + item.getcondition().getcode()
which needless offers opportunities evaluate @ runtime not in fixed list of resources packed in apk.