java - Android XML fatal error

标签 java android xml

我只是更改了 highscores.xml,但当我尝试在菜单中选择 Highscores 时突然出现一些奇怪的错误。 日志猫

12-20 20:30:23.972: INFO/ActivityManager(58): Displayed activity game.main/game.mainmenu.MainMenuActivity: 2166 ms (total 101457 ms)
12-20 20:30:29.172: DEBUG/dalvikvm(123): GC_EXPLICIT freed 893 objects / 48888 bytes in 143ms
12-20 20:30:34.233: DEBUG/dalvikvm(197): GC_EXPLICIT freed 93 objects / 8144 bytes in 169ms
12-20 20:30:38.333: INFO/ActivityManager(58): Starting activity: Intent { cmp=game.main/game.mainmenu.Highscores }
12-20 20:30:38.533: DEBUG/AndroidRuntime(362): Shutting down VM
12-20 20:30:38.533: WARN/dalvikvm(362): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-20 20:30:38.553: ERROR/AndroidRuntime(362): FATAL EXCEPTION: main
12-20 20:30:38.553: ERROR/AndroidRuntime(362): java.lang.RuntimeException: Unable to start activity ComponentInfo{game.main/game.mainmenu.Highscores}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.os.Looper.loop(Looper.java:123)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at java.lang.reflect.Method.invokeNative(Native Method)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at java.lang.reflect.Method.invoke(Method.java:521)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at dalvik.system.NativeStart.main(Native Method)
12-20 20:30:38.553: ERROR/AndroidRuntime(362): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ListActivity.onContentChanged(ListActivity.java:245)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.Activity.setContentView(Activity.java:1647)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at game.mainmenu.Highscores.onCreate(Highscores.java:15)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-20 20:30:38.553: ERROR/AndroidRuntime(362):     ... 11 more
12-20 20:30:38.563: WARN/ActivityManager(58):   Force finishing activity game.main/game.mainmenu.Highscores
12-20 20:30:38.563: WARN/ActivityManager(58):   Force finishing activity game.main/game.mainmenu.MainMenuActivity
12-20 20:30:39.091: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{45028190 game.main/game.mainmenu.Highscores}
12-20 20:30:41.193: INFO/Process(362): Sending signal. PID: 362 SIG: 9
12-20 20:30:41.293: INFO/ActivityManager(58): Process game.main (pid 362) has died.
12-20 20:30:41.293: INFO/WindowManager(58): WIN DEATH: Window{450b3e40 game.main/game.mainmenu.MainMenuActivity paused=true}
12-20 20:30:45.032: DEBUG/dalvikvm(258): GC_EXPLICIT freed 31 objects / 1448 bytes in 128ms
12-20 20:30:49.573: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44f4d640 game.main/game.mainmenu.MainMenuActivity}
12-20 20:30:49.642: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{45028190 game.main/game.mainmenu.Highscores}

Highscores.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget32"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Johonunu"
            android:padding="3dip" />
        <TextView android:text="10000" android:gravity="right"
            android:padding="3dip" />
    </TableRow>
</TableLayout>

高分 Activity

package game.mainmenu;

import game.main.R;
import android.app.Activity;
import android.app.ListActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;

public class Highscores extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.highscores);      


    }
}

主菜单 xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bckgr2"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TableLayout
android:id="@+id/widget28"
android:layout_width="295px"
android:layout_height="600px"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
>
<Button
android:id="@+id/StartGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/startgame_button"
>
</Button>
<TextView
android:id="@+id/widget34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
<Button
android:id="@+id/Help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/help_button" 
>
</Button>
<TextView
android:id="@+id/widget35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
<Button
android:id="@+id/Highscores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/highscores_button" 
>
</Button>
<TextView
android:id="@+id/widget36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
<Button android:id="@+id/Quit" android:background="@drawable/quit_button" android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>

</TableLayout>
</RelativeLayout>

主菜单 Activity

package game.mainmenu;

import game.main.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class MainMenuActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        final Activity t = this;
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN );
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.main);

        Button StartGameButton = (Button)findViewById(R.id.StartGame);//кнопка начала игры
        StartGameButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent StartGameIntent = new Intent(MainMenuActivity.this, StartGame.class);
                startActivity(StartGameIntent);
            }
        });

        Button HelpButton = (Button)findViewById(R.id.Help);//кнопка help
        HelpButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent HelpIntent = new Intent(MainMenuActivity.this, Help.class);
                startActivity(HelpIntent);
            }
        });

        Button OptionsButton = (Button)findViewById(R.id.Highscores);//кнопка 
        OptionsButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent OptionsIntent = new Intent(MainMenuActivity.this, Highscores.class);
                startActivity(OptionsIntent);
            }
        });

        Button QuitButton = (Button)findViewById(R.id.Quit);//кнопка 
        QuitButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                t.finish();//завершаем работу приложения
            }
        });


    }

}

它在高分 xml 中工作时是这样的

<?xml version="1.0" encoding="utf-8" ?> 
- <RelativeLayout android:id="@+id/widget32" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
  <TextView android:text="This is where you would show any options your game has" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
  </RelativeLayout>

但是当我把它改回来时 - 错误并没有消失/发生了什么?我该如何解决这个问题?

最佳答案

您一定还更改了其他内容。您的 Highscores Activity 类正在扩展 ListActivity,这要求您的布局 xml 中存在一个 ListView,其 id 为 android.R.id.list,例如

     <ListView  
     android:id="@android:id/list"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     />

关于java - Android XML fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8581873/

相关文章:

Java 字符串解析

java - 为 cron 作业配置 Java GAE Appstats

android - SQLite 使用 ContentValues 和 BigInteger 数据类型?

java - 在架构定义中创建具有空白命名空间的嵌套元素

java - 无法从 JAR 文件中读取 TLD "META-INF/c.tld"

java - 在Java中将n小时添加到日期?

android - 如何将 android 的 SQLite 作为内存数据库刷新到 sd?

android - DialogFragment 中的 MapFragment

c# - 使用 xsd.exe 反序列化 - 如何反序列化为对象,而不是数据集?

java - 如何删除无效的 XML 元素