错误在获取资源编号值时没有包标识符 [英] ERROR No package identifier when getting value for resource number

查看:33
本文介绍了错误在获取资源编号值时没有包标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个活动在同一个包中

第二个活动使用第二个布局文件

Second activity uses second layout file

setContentView(R.layout.main2);

Second_Activity 中这一行的错误.

Errors on this line in the Second_Activity.

EditText text1 = (EditText) findViewById(R.id.EditText03);

这是 Second_Activity 的布局文件.

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>

这是 LogCat 窗口中的错误

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 

邮件.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

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>

清单xml文件

    <activity android:name=".ActivityTwo"/>

推荐答案

当我尝试使用 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

TextView.setText( int resId );

而且由于没有具有该值的资源,所以它不起作用.

And since there wasn't a resource with that value, it wouldn't work.

这篇关于错误在获取资源编号值时没有包标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆