2010-10-05 55 views
2

我需要將Activity更改爲ListActivity。但我無法啓動我的項目......我需要更改manifest.xml嗎?Activity之間有什麼區別ListActivity?

或者我該如何將屏幕從Activity更改爲ListActivity?與startActivity(new Intent(this, list.class))有什麼不同嗎?

10-05 17:34:54.722: ERROR/AndroidRuntime(11550): java.lang.RuntimeException: Unable to start activity ComponentInfo{spexco.hus.cepvizyon/spexco.hus.cepvizyon.CepVizyon}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.os.Looper.loop(Looper.java:123) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at java.lang.reflect.Method.invoke(Method.java:521) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at dalvik.system.NativeStart.main(Native Method) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ListActivity.onContentChanged(ListActivity.java:236) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.Activity.setContentView(Activity.java:1622) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at spexco.hus.cepvizyon.CepVizyon.onCreate(CepVizyon.java:21) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
10-05 17:34:54.722: ERROR/AndroidRuntime(11550):  ... 11 more 
10-05 17:34:55.432: ERROR/PowerManagerService(129): setPowerState SystemProperties.get siBefornormal 
10-05 17:35:01.872: ERROR/PowerManagerService(129): setPowerState SystemProperties.get siBefornormal 




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

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
           WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.main); 
     ListView list=(ListView) findViewById(R.id.list); 
     ImageButton b1 = (ImageButton) findViewById(R.id.menu_mycameras); 
     ImageButton b2 = (ImageButton) findViewById(R.id.menu_aboutus); 
     ImageButton b3 = (ImageButton) findViewById(R.id.menu_help); 

     b1.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       Intent intent=new Intent(CepVizyon.this, CameraSelectScreen.class); 
       startActivity(intent); 

       // TODO Auto-generated method stub 

      } 
     }); 
     b2.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       Intent intent=new Intent(CepVizyon.this,MainActivity.class); 
       startActivity(intent); 
       // TODO Auto-generated method stub 

      } 
     }); 
     b3.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 


      } 
     }); 
    } 
} 

這是我的課..

,這是我的main.xml我不使用列表那裏,我把它錯誤堆棧。但沒有改變。

<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical" android:layout_weight="3"> 

<ImageButton android:layout_weight="1" android:id="@+id/menu_mycameras" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/menu_cameras"> 
</ImageButton> 
<ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" ></ListView> 
<ImageButton 
    android:paddingTop="20px" 
    android:layout_weight="1" android:id="@+id/menu_aboutus" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/menu_aboutus"> 
</ImageButton> 

<ImageButton android:layout_weight="1" android:id="@+id/menu_help" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/menu_help"> 
</ImageButton> 

</LinearLayout> 

+0

你可以請你發佈你的LogCat中的stacktrace/error嗎? – WarrenFaith 2010-10-05 14:31:04

+0

好吧,它有.. – atasoyh 2010-10-05 14:37:57

+1

這將有助於,如果你也可以發佈你的main.xml佈局文件。 – Janusz 2010-10-05 14:50:44

回答

6

你的ListView的ID必須是:「@android:id/list」。這樣ListActivity會找到它。

1

嘗試閱讀堆棧跟蹤。它告訴你到底需要什麼:「你的內容必須有一個ListView的id屬性是'android.R.id.list'」

+0

我讀過它。 ı寫在我的maın.xml列表中,.. – atasoyh 2010-10-05 14:40:51

+1

benvd我認爲你是對的,但沒有必要被粗魯 – Janusz 2010-10-05 14:51:04

+5

這是如何粗魯?我只是簡單地陳述事實。我應該在表情中塗抹我的話還是什麼? – benvd 2010-10-05 15:17:16

相關問題