2011-12-20 6 views
0

私は単にhighscores.xmlを変更しますが、突然私はメニューでハイスコアを選択しようとすると奇妙なエラーが発生します。 LogCatAndroid 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 dosen't /何が起こりましたか?どうすればこの問題を解決できますか?

答えて

4

変更が必要です。あなたのHighscoresアクティビティクラスはListActivityを拡張しています。リストビューは、あなたのレイアウトxmlにidとandroid.R.id.listという名前で存在する必要があります。

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

ありがとうございます!私はそれを実現しなかった= / – user1107378

2

いずれの方法でも動作してはいけません。レイアウトでListViewを使用していない場合、HighScoresアクティビティはListActivityを拡張しません。代わりに、アクティビティから拡張します。

0

あなたのエラーは述べています{game.main/game.mainmenu.Highscores}:java.lang.RuntimeException:あなたのコンテンツは、そのID属性 'android.R.id.list' でリストビューを持っている必要があります。あなたのHighscoresクラスはリストアビリティですから、リストを追加する必要があります。クラスをアクティビティに変更してみてください。