2011-12-20 67 views
0

我只是改變highscores.xml,但突然間,當我嘗試在菜單中選擇Highscores時,出現了一些奇怪的錯誤。 logcat的Android XML致命錯誤

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> 

榜活動

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


    } 
} 

MainMenu的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> 

主菜單活動

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> 

但是當我改回來 - 錯誤這麼想的disapperaed /發生了什麼?我怎麼解決這個問題?

回答

4

你必須改變別的東西。您的Highscores活動類正在擴展ListActivity,這需要ListView出現在佈局xml中,其ID爲android.R.id.list,例如

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

哦謝謝!我沒有意識到它= / – user1107378 2011-12-20 21:14:06

2

它不應該有任何工作方式。如果您在佈局中未使用ListView,則HighScores活動不應擴展ListActivity。相反,從Activity擴展。

0

你的錯誤說:{game.main/game.mainmenu.Highscores}:了java.lang.RuntimeException:你的內容必須有一個ListView其id屬性爲 'android.R.id.list'。你的Highscores類是一個列表活動,那麼你必須添加一個列表。嘗試將該類更改爲一個活動。