大家好,我目前正在尝试解决一个奇怪的问题。我尽可能地减少了我的应用程序,以便清楚地向您展示问题。
我可以像这样使用主布局启动我的应用程序:
public class AndroidReaderActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
有了这个 main.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
如果我在布局目录中添加一个名为 list.xml 的新布局,我的应用程序崩溃了……我不明白。这是日志(一旦我添加了新的 xml,程序就找不到 main.xml 资源)
05-16 03:00:14.631: E/AndroidRuntime(4399): FATAL EXCEPTION: main
05-16 03:00:14.631: E/AndroidRuntime(4399): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infotel/com.infotel.AndroidReaderActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.os.Looper.loop(Looper.java:137)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-16 03:00:14.631: E/AndroidRuntime(4399): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 03:00:14.631: E/AndroidRuntime(4399): at java.lang.reflect.Method.invoke(Method.java:511)
05-16 03:00:14.631: E/AndroidRuntime(4399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-16 03:00:14.631: E/AndroidRuntime(4399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-16 03:00:14.631: E/AndroidRuntime(4399): at dalvik.system.NativeStart.main(Native Method)
05-16 03:00:14.631: E/AndroidRuntime(4399): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.content.res.Resources.getValue(Resources.java:1018)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2105)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.content.res.Resources.getLayout(Resources.java:857)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-16 03:00:14.631: E/AndroidRuntime(4399): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.Activity.setContentView(Activity.java:1835)
05-16 03:00:14.631: E/AndroidRuntime(4399): at com.infotel.AndroidReaderActivity.onCreate(AndroidReaderActivity.java:92)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.Activity.performCreate(Activity.java:4465)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-16 03:00:14.631: E/AndroidRuntime(4399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
谢谢你们的帮助:D
编辑
这是我的 list.xml
<?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="100dip" >
<ImageView
android:id="@+list/thumb"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+list/text"
android:layout_toRightOf="@+list/thumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:layout_marginLeft="10dip"
android:layout_centerVertical="true"
android:singleLine="true"
android:ellipsize="end"
android:textStyle="bold"
/>
</RelativeLayout>
还有我的 manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.infotel"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AndroidReaderActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>