Android resource id not found

I created a new project goal 8 for Android, with default activity

I assigned a textview id with the 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> 

This is a unique activity.

 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 "); } } 

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 

I am using sdk r11 and adt v10.

I think there is a problem with the resources.

Any idea?

Thanks.

0
source share
1 answer

Have you declared your activity in your manifest.xml?

Example activity declaration:

 <?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> 
0
source

Source: https://habr.com/ru/post/950238/


All Articles