2012-07-16 61 views
0

這裏是我主要的Java文件,MainActivity.java「意外停止」 試10000次修復

package com.myprojects.schecklist; 
import android.app.ListActivity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class MainActivity extends ListActivity { 

    private ListView listView; 
    private String[] items = { "Activity1", "Activity2" }; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     listView = (ListView) findViewById(R.id.mylist); 
     listView.setAdapter(new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, items)); 

    } 
} 

這裏是activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/mylist" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

AndroidManifest.xml中

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.myprojects.schecklist" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="10" 
     android:targetSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

至少我試過4-5個方法來解決這個問題。最後我試了項目>清除和它不固定。 我嘗試了一切,至少我正在關於它的三天工作。怎麼了?我會瘋了。

+0

無需查看logcat視圖就很難修復。但問題可能是您的ListView ID。如果您使用的是ListActivity,那麼ListView id應該是@android:id/list。 – Ran 2012-07-16 10:30:06

+0

嘗試使用Activity而不是ListActivity。 – AkashG 2012-07-16 10:31:10

+0

一切都很好,只能用'Activity'而不是'ListActivity'來擴展。 – AkashG 2012-07-16 10:35:40

回答

0

變化:

new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, items) 

有:

new ArrayAdapter<String>(this, 
    android.R.layout.simple_list_item_1, android.R.id.text1, items) 
0

不是擴展ListActivity儘量延長Activity或更改您的

<ListView 
     android:id="@+id/mylist" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

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

我不能投票給你。我會瘋了:/ – tayfun 2012-07-16 10:46:17

+0

沒問題。但如果它能幫助你,你仍然可以接受這個答案。 – 2012-07-20 11:01:44