Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>

like image 998
tmcham Avatar asked Feb 11 '11 18:02

tmcham


3 Answers

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

like image 146
SevenSecondSoftware Avatar answered Nov 16 '22 23:11

SevenSecondSoftware


Android doesn't allow uppercase resource names

Rename

R.id.game_Answer1

to

game_answer_one

etc for the other's you have

like image 29
Blundell Avatar answered Nov 17 '22 00:11

Blundell


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

like image 1
JanB Avatar answered Nov 16 '22 23:11

JanB