我有這個課的問題。我按下按鈕時會調用此活動。當我將Activity擴展到這個類時,程序會進入類,但是當我擴展ListActiviy並且單擊按鈕時,調試器會用紅色的詞語「源代碼未找到」告訴我,而不是其他任何東西,甚至不是logcat中的東西。 請告訴我,如果在此活動或清單的xml文件中缺少某些內容。爲什麼我更改擴展Activity以擴展ListActivity時會出現「未找到源」?
這是課外活動:
public class SeeAllEntriesActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_entries);
ActivitiesObjects ao = (ActivitiesObjects)this.getApplication();
List<Customer> listOfCostumer = ao.getListOfCustomers();
ListAdapter listAdapter = new ArrayAdapter(this, R.layout.activity_all_entries, listOfCostumer);
ListView listViewCustomer = (ListView) findViewById(R.id.listViewCustomer);
listViewCustomer.setAdapter(listAdapter);
}
}
這是活動的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="all entries" />
<ListView
android:id="@+id/listViewCustomer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
這是清單的XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application android:name="com.example.testapp.ActivitiesObjects" android:label="@string/app_name">
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>
<activity android:name="CreateActivity"></activity>
<activity android:name="SeeAllEntriesActivity"></activity>
</application>
</manifest>
在此先感謝, alex
謝謝你的快速回答。我像你說的那樣改變了代碼,這個活動真的在模擬器上打開,沒有任何錯誤。不幸的是,當列表包含數據時,他顯示錯誤,但我認爲這是因爲我必須編寫一個適配器。但是,謝謝,現在我可以專注於這個問題:) –