我是 android 开发的初学者并且遇到了问题。我正在制作一个简单的应用程序,在列表视图中显示总统。但是当我尝试在模拟器上运行它时,我得到了这个错误:Source not Found net.learn2develop.Listfragmentexample.ListFragmentExampleActivity。这是我的java文件代码:
package net.learn2develop.Listfragmentexample;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Fragment1 extends ListFragment {
String[] presidents = {
"Dwight D. Eisenhower",
"John F. Kennedy",
"Lyndon B. Johnson",
"Richard Nixon",
"Gerald Ford",
"Jimmy Carter",
"Ronald Reagen",
"George H. W. Bush",
"Bill Clinton",
"George W. Bush",
"Barack Obama"
};
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment1, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, presidents));
}
public void onListItemClick(ListView parent, View v,
int position, long id)
{
Toast.makeText(getActivity(),
"You have selected item : " + presidents[position],
Toast.LENGTH_SHORT).show();
}
}
这是 main.xml 的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<fragment
android:id="@+id/fragment1"
android:name="net.learn2develop.ListFragmentExample.Fragment1"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="200dp" />
<fragment
android:id="@+id/fragment2"
android:name="net.learn2develop.ListFragmentExample.Fragment1"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="300dp" />
</LinearLayout>
这是 fragment1.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/android:list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
这是我的 Logcat 跟踪:
[2013-04-25 18:31:55 - ListFragmentExample] Android Launch!
[2013-04-25 18:31:55 - ListFragmentExample] adb is running normally.
[2013-04-25 18:31:55 - ListFragmentExample] Performing net.learn2develop.Listfragmentexample.ListFragmentExampleActivity activity launch
[2013-04-25 18:31:55 - ListFragmentExample] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Android_4.0'
[2013-04-25 18:31:55 - ListFragmentExample] Uploading ListFragmentExample.apk onto device 'emulator-5554'
[2013-04-25 18:31:56 - ListFragmentExample] Installing ListFragmentExample.apk...
[2013-04-25 18:32:03 - ListFragmentExample] Success!
[2013-04-25 18:32:03 - ListFragmentExample] Starting activity net.learn2develop.Listfragmentexample.ListFragmentExampleActivity on device emulator-5554
[2013-04-25 18:32:05 - ListFragmentExample] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=net.learn2develop.Listfragmentexample/.ListFragmentExampleActivity }
[2013-04-25 18:32:06 - ListFragmentExample] Attempting to connect debugger to 'net.learn2develop.Listfragmentexample' on port 8666
这是我的清单代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.Listfragmentexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="net.learn2develop.Listfragmentexample.ListFragmentExampleActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
有人可以在这里填写吗?我不知道我做错了什么。任何帮助深表感谢!