ERROR No package identifier when getting value for resource number

23

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"
        android: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"/>

android
android-layout
android-resources
asked on Stack Overflow Aug 3, 2010 by Dean-O • edited Mar 17, 2014 by Mario Lenci

11 Answers

110

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.

answered on Stack Overflow Apr 27, 2011 by John Weidner
42

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));

answered on Stack Overflow Jun 27, 2013 by 楊惟鈞 • edited Aug 4, 2014 by CoderCroc
9

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)).

answered on Stack Overflow Sep 26, 2011 by Henok • edited Sep 26, 2011 by Flexo
7

Just for the protocol, You could also use:

TextView.setText("" + intVar) instead of TextView.setText(intVar)

answered on Stack Overflow Jan 13, 2012 by Paul • edited Jan 13, 2012 by Abimaran Kugathasan
6

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)

answered on Stack Overflow Apr 12, 2018 by Vignan Nani
4

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.

answered on Stack Overflow Jun 26, 2018 by nekiala
4

From Android TextView Documentation:

  • setText(int resid) Sets the text to be displayed using a string resource identifier.
answered on Stack Overflow Apr 11, 2019 by Rigoberto Torres • edited Apr 12, 2019 by Eduardo Baitello
2

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);

answered on Stack Overflow Feb 28, 2012 by Lucy Lu • edited May 26, 2012 by EdChum
2

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.

answered on Stack Overflow Feb 2, 2018 by Ankit Gupta
0

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.

answered on Stack Overflow Sep 2, 2015 by saintjab
0

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.

answered on Stack Overflow May 29, 2016 by Vishnu

User contributions licensed under CC BY-SA 3.0