這裏是我主要的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個方法來解決這個問題。最後我試了項目>清除和它不固定。 我嘗試了一切,至少我正在關於它的三天工作。怎麼了?我會瘋了。
無需查看logcat視圖就很難修復。但問題可能是您的ListView ID。如果您使用的是ListActivity,那麼ListView id應該是@android:id/list。 – Ran 2012-07-16 10:30:06
嘗試使用Activity而不是ListActivity。 – AkashG 2012-07-16 10:31:10
一切都很好,只能用'Activity'而不是'ListActivity'來擴展。 – AkashG 2012-07-16 10:35:40