Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi dudes
i have this code in class file:
Java
ublic class MainActivity extends ListActivity {

	 DBAdapter db;
	 List <Story> storyList;
	 ListView lvMain;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	Log.i("#%%%%%%%%%%%%%%%%%%%%%","1");
    	
        super.onCreate(savedInstanceState);
        Log.i("#%%%%%%%%%%%%%%%%%%%%%","1.5");
        setContentView(R.layout.activity_main2);
        Log.i("#%%%%%%%%%%%%%%%%%%%%%","2");
        db.open();
        storyList=db.GetAllItems();
        Log.i("#%%%%%%%%%%%%%%%%%%%%%","3");
        if (storyList.size()==0)//import database if local database is empty.
        {
        	Log.i("#%%%%%%%%%%%%%%%%%%%%%","4");
        	InputStream sourcePath;
        	OutputStream destPath;
			try {
				sourcePath = getBaseContext().getAssets().open("StoryDB");
			    destPath=new FileOutputStream( "/data/data/"+getPackageName()+"/databases/data");
			    Log.i("#%%%%%%%%%%%%%%%%%%%%%","5");
			    CopyDB(sourcePath,destPath);
			    Log.i("#%%%%%%%%%%%%%%%%%%%%%","5.5");
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
       			
        
        	Log.i(DBAdapter.TAG,"@@@DB copy finished.");
        	 
        	storyList=db.GetAllItems();
        	
        }
    }

and in xml file (activity_main) i have this:
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button1"
        android:layout_toRightOf="@+id/button1"
        android:text="Button" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button2"
        android:layout_toRightOf="@+id/button2"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="25dp"
        android:text="Button" />

    <ListView
        android:id="@+id/lvMain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="14dp" >
    </ListView>

</RelativeLayout>

now i wanna start that i get this error:
02-14 21:06:57.715: W/ActivityThread(19498): Application behnam.mohammadi.book1 can be debugged on port 8100...
02-14 21:06:57.745: I/#%%%%%%%%%%%%%%%%%%%%%(19498): 1
02-14 21:06:57.745: I/#%%%%%%%%%%%%%%%%%%%%%(19498): 1.5
02-14 21:06:57.815: D/AndroidRuntime(19498): Shutting down VM
02-14 21:06:57.815: W/dalvikvm(19498): threadid=1: thread exiting with uncaught exception (group=0x40f922a0)
02-14 21:06:57.835: E/AndroidRuntime(19498): FATAL EXCEPTION: main
02-14 21:06:57.835: E/AndroidRuntime(19498): java.lang.RuntimeException: Unable to start activity ComponentInfo{behnam.mohammadi.book1/behnam.mohammadi.book1.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ActivityThread.access$600(ActivityThread.java:140)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.os.Looper.loop(Looper.java:137)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ActivityThread.main(ActivityThread.java:4898)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at java.lang.reflect.Method.invokeNative(Native Method)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at java.lang.reflect.Method.invoke(Method.java:511)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at dalvik.system.NativeStart.main(Native Method)
02-14 21:06:57.835: E/AndroidRuntime(19498): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ListActivity.onContentChanged(ListActivity.java:243)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:311)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.Activity.setContentView(Activity.java:1924)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at behnam.mohammadi.book1.MainActivity.onCreate(MainActivity.java:30)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.Activity.performCreate(Activity.java:5206)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
02-14 21:06:57.835: E/AndroidRuntime(19498): 	... 11 more
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900