ERROR No package identifier when getting value for resource number
Both activities are in the same package
Second activity uses second layout file
setContentView(R.layout.main2);
Errors on this line in the Second_Activity.
EditText text1 = (EditText) findViewById(R.id.EditText03);
Here is the layout file for the Second_Activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer Is : " >
</TextView>
<EditText
android:id="@+id/EditText03"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
andr开发者_如何学Gooid:text="Calling an intent" >
</Button>
</LinearLayout>
Here are the errors in the LogCat window
08-01 19:32:20.340: WARN/ResourceType(8875): No package identifier when getting value for resource number 0x00000005
08-01 19:32:20.390: ERROR/AndroidRuntime(8875): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x5
mail.xml
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="First Number : ">
</TextView>
<EditText
android:id="@+id/EditText01"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Second Number: ">
</TextView>
<EditText
android:id="@+id/EditText02"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
secondscreen.xml
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Answer Is : ">
</TextView>
<EditText
android:id="@+id/main2EditText01"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
manifest xml file
<activity android:name=".ActivityTwo"/>
I got this same error message when I tried to use TextView.setText passing a char instead of a String. This makes sense since the char would be promoted to an int which meant that I was really calling the
TextView.setText( int resId );
And since there wasn't a resource with that value, it wouldn't work.
face with the same error
finally i found its not a error due to your xml layout
somewhere in your code set TextView.setText(int)
try TextView.setText( Integer.toString(int));
When you pass an integer to the TextView.setText()
to be displayed android assumes it is a resource id and that's why you are getting Resource$NotFoundException
. Try converting the int to String before passing it to TextView.setText()
: TextView.setText(String.valueOf(i))
.
Just for the protocol, You could also use:
TextView.setText("" + intVar)
instead of TextView.setText(intVar)
I got the same error while trying to print integer value : TextView.setText(int value). I resolved this error by converting the integer value to string and the i used TextView.setText(converted string value)
I had the same problem before I come to this post.
For me, it was like this: view_element.setText( an_int_value)
.
After casting view_element.setText(String.valueOf(an_int_value));
, everything is okay.
From Android TextView Documentation:
setText(int resid)
Sets the text to be displayed using a string resource identifier.
For me I had to go in the XML file for the button. There I noticed a hard coded string value. I had to remove that, and also I had to use Textview.setText("" + intVar);
It is due to typecast error. You have to try this- TextView.setText(Integer.toString(variable_name));
Here toString is used to convert integer to string for showing text.
I was using Picasso library to load image from the network. The urls are in a ArrayList I wasn't using arraylist.get() to get the position of the url in the ArrayList.
I recently had this problem, when i was trying to integrate SocialAuth libray with my Android application with Android Studio. What was my problem was, some of my resources like facebook icon, were in the mipamp folder. I moved it to drawables folder and the issue got fixed.
精彩评论