Im a beginner to android developing and have run into a problem. Im making a simple app that displays presidents in a List View. But when I try to run it on the emulator, ir gets this error: Source not Found net.learn2develop.Listfragmentexample.ListFragmentExampleActivity. Here is my code for the java file:
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(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();
}
}
Here is the code for the main.xml:
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" >android:id="@+id/fragment1"
android:name="net.learn2develop.ListFragmentExample.Fragment1"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="200dp" />android:id="@+id/fragment2"
android:name="net.learn2develop.ListFragmentExample.Fragment1"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="300dp" />
And here is the code for fragment1.xml:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >android:id="@id/android:list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
Here is my Logcat trace:
[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
Here is my Manifest code:
package="net.learn2develop.Listfragmentexample"
android:versionCode="1"
android:versionName="1.0" >android:minSdkVersion="14"
android:targetSdkVersion="14" />android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="net.learn2develop.Listfragmentexample.ListFragmentExampleActivity"
android:label="@string/app_name" >
Can someone fill me in here? I dont know what im doing wrong. Any help is much appreciated!
.
stackoverflow.comm
No comments:
Post a Comment