Crashing due to "No package identifier when getting value of resource number..."

9

Okay after searching through the various threads that I could find on this topic, and trying everything that seemed to work for the others... I have succumb to the need to post my own issue.

As a total noob to Android and Java, you will have to forgive the need to talk to me like a child :)

I have an app that has 3 activities so far. A main window that works as a navigation screen to choose one of the other two. The first works perfectly, but when I try button number 2... it crashes.

I have some code that I am trying to run onCreate... so when I saw that it was often the XML layout that caused the crash.. I commented out the Java code... and presto the layout loads fine.

putting the code back in, it crashes once again.

Looking in LogCat I see a line that says "No Package identifier when getting value for resource number 0x0000000d"

Then all sorts of lines about fatal exceptions and shutting down the VM.

So, garnering confidence from other posts, I went to the R.java file to see what resource has that ID... and it's not in there. They ALL start with 0x7f... now the ONLY one that ends in "d" is a textview with the ID "game_Answer1". But I am not certain if that is what it's referring to or not.

I did try the Eclipse clean command, as well as deleting the R.java... same issue.

Below is the java code that seems to be crashing... again, hold the laughter at my spaghetti code as this is attempt #2 in Java beyond a hello world app!


import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.Random;
public class playgame extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gamelayout);

    //set up first question
    genQuestion();

}


Random generator = new Random();

public void genQuestion() {
    int i = generator.nextInt(25);
    int correct = generator.nextInt(2)+1;
    TextView g_answera = (TextView) findViewById(R.id.game_Answer1);
    TextView g_answerb = (TextView) findViewById(R.id.game_Answer2);
    TextView g_answerc = (TextView) findViewById(R.id.game_Answer3);


    g_answera.setText("-");
    g_answerb.setText("-");
    g_answerc.setText("-");

    if(correct==1){
        g_answera.setText("!");
    }
    if(correct==2){
        g_answerb.setText("!");
    }
    if(correct==3){
        g_answerc.setText("!");
    }

}

Below is the XML layout associated with this issue... just in case I am missing something obvious:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#ffffff"  android:id="@+id/gamelayoutwrapper">
<RelativeLayout android:layout_height="wrap_content" android:id="@+id/games_animalnameFrame" android:layout_width="fill_parent" android:gravity="right">
    <TextView android:layout_height="wrap_content" android:id="@+id/game_animalname" android:layout_width="fill_parent" android:textSize="60sp" android:layout_alignParentRight="true" android:gravity="right" android:text="__nteater"></TextView>
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content" android:id="@+id/game_animalimageFrame" android:layout_below="@+id/games_animalnameFrame" android:layout_centerInParent="true" android:layout_height="wrap_content" android:gravity="top">
    <ImageView android:id="@+id/game_animalImage" android:src="@drawable/elephant" android:scaleType="fitCenter" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingBottom="10dp"></ImageView>
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content" android:id="@+id/gameLettersFrame" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_centerHorizontal="true" android:background="#cccccc">

            <TextView android:layout_height="wrap_content" android:id="@+id/game_Answer1" android:text="A" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_gravity="left" android:clickable="true" android:textSize="100sp" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:textColor="#090999" android:background="#ccccFF"></TextView>
            <TextView android:layout_height="wrap_content" android:id="@+id/game_Answer2" android:text="B" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_gravity="center_horizontal" android:clickable="true" android:textSize="100sp" android:layout_width="wrap_content" android:layout_centerInParent="true" android:textColor="#090999" android:background="#ffcccc"></TextView>
            <TextView android:layout_height="wrap_content" android:id="@+id/game_Answer3" android:text="C" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_gravity="right" android:clickable="true" android:textSize="100sp" android:layout_width="wrap_content" android:layout_alignParentLeft="false" android:layout_alignParentRight="true" android:textColor="#090999" android:background="#ccffcc"></TextView>

</RelativeLayout>

java
android
xml
debugging
resources
asked on Stack Overflow Feb 11, 2011 by tmcham • edited Feb 11, 2011 by dave.c

7 Answers

50

I ran into this same issue a while ago, I assume that it is fixed but I figured an alternative answer is always welcome :) When using the setText() method you CANNOT send through primitive data types such as int and double, rather convert to string and then send through the string. This fixed my issue when it popped up

answered on Stack Overflow Sep 20, 2011 by SevenSecondSoftware
1

Android doesn't allow uppercase resource names

Rename

R.id.game_Answer1

to

game_answer_one

etc for the other's you have

answered on Stack Overflow Feb 11, 2011 by Blundell
1

I wanted to look at the ID name for a LinearLayout to make sure I was accessing the correct one in my code. This error for me happened because I had forgotten to add an android:id="@+id/myid" into one of my XML layout files (because that file wasn't the focus of my attention at that point!)

answered on Stack Overflow Nov 20, 2014 by JanB
0

in your R.java file, does an id for gamelayout exist? This should be located in public static final class layout { } in the R file? Thats the first important step in determining why your application crashes.

answered on Stack Overflow Feb 11, 2011 by Hakan Ozbay
0

Android (unfortunately) doesn't accept resource identifiers with upper-case letters. Also, make sure you are defining your namespace in the root view.

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/game_answer1" 
            android:text="A" 
            android:paddingLeft="20dp" 
            android:paddingRight="20dp" 
            android:layout_gravity="left" 
            android:clickable="true" 
            android:textSize="100sp" 
            android:layout_alignParentLeft="true" 
            android:textColor="#090999" 
            android:background="#ccccFF"
            />             
    </RelativeLayout>
answered on Stack Overflow Feb 11, 2011 by ptc
0

there might be others errors in your project because of which your R.java is not created well. hence while executing it is not getting the resource with that id. R.id contains id of all the resources in your projects.

answered on Stack Overflow Oct 10, 2013 by Shreenivas Chikati
0

It's quite late to answer, though might be useful for those to will find this thread through search.

The setText method requires the identifier as an argument. So, there should be a string in the values/strings.xml with name like "empty_answer", containing the value "-". In other words, the line like: -

Then the setText should be called like: g_answera.setText(R.string.empty_answer);

Possibly, what happens in your case is that the string "-" was somehow turned into resource id 0x0000000d, which of course doesn't exist in your app. Although it's strange that such code was compiled.

One more comment: in Android it IS POSSIBLE to name resources like IDs with Capital characters. What is NOT possible - to have Capital chars in the NAME of resource files.

answered on Stack Overflow May 24, 2014 by Carrier

User contributions licensed under CC BY-SA 3.0