my activity stops unexpectedly as soon as i run the app in the emulator. What am i doing wrong? Below is my code from the main activity and my android manifest:
package android.Database;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class projectsDatabase extends Activity {
/** Called when the activity is first created. */
SQLiteDatabase myDB = null;
final static String MY_DB_NAME ="projectsDatabase";
final static String MY_DB_TABLE = "projects";
static final int MENU_PROJECTS = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onCreateDBAndDBTabled();
setContentView(R.layout.main);
}
private void onCreateDBAndDBTabled(){
myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
+ " ( _id integer primary key_autoincrement,"+
"Name varchar(100),"+
"Comment varchar(128),"+
"BookingDetails varchar(255),"+
"Project-Kind integer(3))"
+"");
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_PROJECTS, 0, R.string.menuProjects)
.setShortcut('1', 'f')
.setIcon(R.drawable.icon);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case MENU_PROJECTS:
Intent iProjects= new Intent(this, projects.class);
startActivity(iProjects);
return true;
}
return false;
}
}
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".projectsDatabase"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".projects"></activity>
<activity android:name=".projects_New"></activity>
</application>
</manifest>
——————————–EDIT——————————————————-
here is my LogCat output:
02-22 08:48:01.999: DEBUG/AndroidRuntime(819): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
02-22 08:48:02.009: DEBUG/AndroidRuntime(819): CheckJNI is ON
02-22 08:48:02.229: DEBUG/AndroidRuntime(819): --- registering native functions ---
02-22 08:48:02.239: INFO/jdwp(819): received file descriptor 23 from ADB
02-22 08:48:02.969: DEBUG/AndroidRuntime(819): Shutting down VM
02-22 08:48:02.979: DEBUG/dalvikvm(819): DestroyJavaVM waiting for non-daemon threads to exit
02-22 08:48:02.979: DEBUG/dalvikvm(819): DestroyJavaVM shutting VM down
02-22 08:48:02.989: DEBUG/dalvikvm(819): HeapWorker thread shutting down
02-22 08:48:02.989: DEBUG/dalvikvm(819): HeapWorker thread has shut down
02-22 08:48:02.999: DEBUG/jdwp(819): JDWP shutting down net...
02-22 08:48:02.999: DEBUG/jdwp(819): +++ peer disconnected
02-22 08:48:02.999: INFO/dalvikvm(819): Debugger has detached; object registry had 1 entries
02-22 08:48:03.009: DEBUG/dalvikvm(819): VM cleaning up
02-22 08:48:03.019: DEBUG/dalvikvm(819): LinearAlloc 0x0 used 629804 of 4194304 (15%)
02-22 08:48:03.479: DEBUG/AndroidRuntime(829): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
02-22 08:48:03.479: DEBUG/AndroidRuntime(829): CheckJNI is ON
02-22 08:48:03.689: DEBUG/AndroidRuntime(829): --- registering native functions ---
02-22 08:48:03.699: INFO/jdwp(829): received file descriptor 23 from ADB
02-22 08:48:04.439: INFO/ActivityManager(559): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.LAUNCHER} flags=0x10000000 comp={android.Database/android.Database.projectsDatabase} }
02-22 08:48:04.449: DEBUG/AndroidRuntime(829): Shutting down VM
02-22 08:48:04.459: DEBUG/dalvikvm(829): DestroyJavaVM waiting for non-daemon threads to exit
02-22 08:48:04.469: DEBUG/dalvikvm(829): DestroyJavaVM shutting VM down
02-22 08:48:04.469: DEBUG/dalvikvm(829): HeapWorker thread shutting down
02-22 08:48:04.469: DEBUG/dalvikvm(829): HeapWorker thread has shut down
02-22 08:48:04.479: DEBUG/jdwp(829): JDWP shutting down net...
02-22 08:48:04.479: DEBUG/jdwp(829): +++ peer disconnected
02-22 08:48:04.479: INFO/dalvikvm(829): Debugger has detached; object registry had 1 entries
02-22 08:48:04.489: DEBUG/dalvikvm(829): VM cleaning up
02-22 08:48:04.509: DEBUG/dalvikvm(829): LinearAlloc 0x0 used 639228 of 4194304 (15%)
————————————–Edit 2———————————————–
here is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
I ran your code, the first LogCat exception gives a good clue:
My database helper is setup like this instead:
I think your error lies with the “key_autoincrement” (as the error message implies), try writing it in 2 words as opposed to separating it with an underscore?