Reputation: 33
I have started doing some exercises from an android development book. All i have done is
create a project
Input some code
package com.wuhu.testapps;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AndroidbasicsActivity extends ListActivity {
String tests[] = {"LifeCycleTest", "SingleTouchTest","MultiTouchTest"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setListAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,tests));
}
protected void onListItemClick( ListView list, View view, int position, long id)
{
super.onListItemClick(list, view, position, id );
String testName = tests[position];
try
{
Class clazz = Class.forName("com.wuhu.testapps." + testName);
Intent intent = new Intent( this, clazz );
startActivity(intent);
}
catch( ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
Run as android application
VM starts with activity in the background, but an error keeps appearing 'the process android.process.acore has stopped unexpectedly' Force close.
The first few lines of error in logcat are as follows :
02-04 03:05:21.218: ERROR/ContactsProvider(343): Cannot start provider
02-04 03:05:21.218: ERROR/ContactsProvider(343): java.lang.IllegalStateException: error upgrading the database to version 353
02-04 03:05:21.218: ERROR/ContactsProvider(343): at com.android.providers.contacts.ContactsDatabaseHelper.onUpgrade(ContactsDatabaseHelper.java:1545)
02-04 03:05:21.218: ERROR/ContactsProvider(343): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)
02-04 03:05:21.218: ERROR/ContactsProvider(343): at com.android.providers.contacts.ContactsDatabaseHelper.getWritableDatabase(ContactsDatabaseHelper.java:2550)
02-04 03:05:21.218: ERROR/ContactsProvider(343): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
02-04 03:05:21.218: ERROR/ContactsProvider(343): at com.android.providers.contacts.LegacyApiSupport.<init>(LegacyApiSupport.java:525)
Am not sure what is going wrong, can anyone help me? Tried searching for an answer but to avail. Thanks in advance,
Upvotes: 0
Views: 5589
Reputation: 49
The problem is not with your code. You should get the same error even if you virtual device directly.
Creating a new Virtual Device works well. Make sure to delete the old one.
Upvotes: 1
Reputation: 21
I fixed it by the following method.
Android Virtual Device Manager > New
Remake Android Virtual Devices. Old setting delete.
Upvotes: 2
Reputation: 42
from Exception , it looks like sqlite cause this problem, Anriod has Mechanism, It can auto update your database, if you override onUpgrade method , just like the following:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "DROP TABLE IF EXISTS " + TABLE_NAME;
db.execSQL(sql);
onCreate(db);
}
Upvotes: 1
Reputation: 29672
Try following, Remove Comment from your below line.
//setContentView(R.layout.main);
to setContentView(R.layout.main);
and then try running again.
Upvotes: 0