获取资源编号值时出现错误无包标识符
两个活动都在同一个包中
第二个活动使用第二个布局文件
setContentView(R.layout.main2);
Second_Activity 中的这一行出现错误。
EditText text1 = (EditText) findViewById(R.id.EditText03);
这是 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>
中的错误
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
以下是 LogCat 窗口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>
第二屏.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>
清单 xml 文件
<activity android:name=".ActivityTwo"/>
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"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
当我尝试使用 TextView.setText 传递字符而不是字符串时,我得到了同样的错误消息。这是有道理的,因为 char 将被提升为 int,这意味着我实际上是在调用
,并且由于没有具有该值的资源,所以它不起作用。
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
And since there wasn't a resource with that value, it wouldn't work.
面对同样的错误
最后我发现它不是一个错误,因为你
的代码集中某处的 xml 布局
TextView.setText(int)
尝试
TextView.setText( Integer.toString(int)) ;
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));
当您将一个整数传递给要显示的
TextView.setText()
时,Android 会假定它是一个资源 ID,这就是您收到Resource$NotFoundException
的原因。尝试将 int 转换为 String,然后再将其传递给TextView.setText()
:TextView.setText(String.valueOf(i))
。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 gettingResource$NotFoundException
. Try converting the int to String before passing it toTextView.setText()
:TextView.setText(String.valueOf(i))
.仅对于协议,您还可以使用:
TextView.setText("" + intVar)
而不是TextView.setText(intVar)
Just for the protocol, You could also use:
TextView.setText("" + intVar)
instead ofTextView.setText(intVar)
我在尝试打印整数值时遇到相同的错误:TextView.setText(int value)。
我通过将整数值转换为字符串和我使用的来解决了这个错误
TextView.setText(转换后的字符串值)
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)
在我写这篇文章之前我也遇到了同样的问题。
对我来说,它是这样的:
view_element.setText(an_int_value)
。转换后
view_element.setText(String.valueOf(an_int_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.来自 Android TextView 文档:
From Android TextView Documentation:
这是由于类型转换错误造成的。
你必须尝试这个——
TextView.setText(Integer.toString(variable_name));
这里 toString 用于将整数转换为字符串以显示文本。
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.
对我来说,我必须进入按钮的 XML 文件。在那里我注意到一个硬编码的字符串值。我必须删除它,而且我还必须使用 Textview.setText("" + intVar);
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);
我正在使用毕加索库从网络加载图像。 url 位于 ArrayList 中,我没有使用 arraylist.get() 来获取 url 在 ArrayList 中的位置。
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.
我最近遇到了这个问题,当我尝试使用 Android Studio 将 SocialAuth 库与我的 Android 应用程序集成时。我的问题是,我的一些资源(例如 facebook 图标)位于 mipamp 文件夹中。我将其移至 drawables 文件夹,问题得到解决。
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.