本文介绍了不是的android找到资源ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个新的Android项目的目标8,使用默认的活动
i've created a new android project target 8, with default activity
我分配一个ID与文本的TextView的Hello world。
I've assigned an id to textview with text "Hello world".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tvProva"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
这是唯一的活动
package it.prova;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class EmptyActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.tvProva);
tv.setText("Prova ");
}
}
这是logcat的
And this is logcat
02-24 16:09:25.374: ERROR/AndroidRuntime(537): Caused by: java.lang.NullPointerException
02-24 16:09:25.374: ERROR/AndroidRuntime(537): at it.prova.EmptyActivity.onCreate(EmptyActivity.java:22)
02-24 16:09:25.374: ERROR/AndroidRuntime(537): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-24 16:09:25.374: ERROR/AndroidRuntime(537): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-24 16:09:25.374: ERROR/AndroidRuntime(537): ... 11 more
我使用的SDK R11和ADT V10。
I'm using sdk r11 and adt v10.
我觉得这是有问题的资源。
I think there is a problem with resources.
任何想法?
感谢。
推荐答案
有你宣布你的manifest.xml您的活动?
have you declared your activity on your manifest.xml ?
活动的声明示例:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.warriorpoint.taxman2"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity1"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
这篇关于不是的android找到资源ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!