控制台显示以下评论。但在模拟器所需的应用程序中不显示任何内容。
[2013-07-20 12:09:41 - searchdb] Android Launch!
[2013-07-20 12:09:41 - searchdb] adb is running normally.
[2013-07-20 12:09:41 - searchdb] Performing com.example.searchdb.MainActivity activity launch
[2013-07-20 12:09:41 - searchdb] Automatic Target Mode: Preferred AVD 'Api17' is available on emulator 'emulator-5554'
[2013-07-20 12:09:46 - searchdb] Uploading searchdb.apk onto device 'emulator-5554'
[2013-07-20 12:09:46 - searchdb] Installing searchdb.apk...
[2013-07-20 12:10:00 - searchdb] Success!
[2013-07-20 12:10:01 - searchdb] Starting activity com.example.searchdb.MainActivity on device emulator-5554
这是 logcat 文件。我工作区中的所有项目都存在同样的问题。我的 avd 有问题,所以我从不继续我的项目。请帮助我解决问题。提前致谢。
日志文件
07-20 07:13:42.034: E/System(11988): ******************************************
07-20 07:13:42.114: E/System(11988): ************ Failure starting core service
07-20 07:13:42.114: E/System(11988): java.lang.RuntimeException: Unable to get provider com.android.providers.settings.SettingsProvider: android.database.sqlite.SQLiteException: Can't downgrade database from version 95 to 94
07-20 07:13:42.114: E/System(11988): at android.app.ActivityThread.installProvider(ActivityThread.java:4820)
07-20 07:13:42.114: E/System(11988): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4430)
07-20 07:13:42.114: E/System(11988): at android.app.ActivityThread.installSystemProviders(ActivityThread.java:4968)
07-20 07:13:42.114: E/System(11988): at com.android.server.am.ActivityManagerService.installSystemProviders(ActivityManagerService.java:6898)
07-20 07:13:42.114: E/System(11988): at com.android.server.ServerThread.run(SystemServer.java:282)
07-20 07:13:42.114: E/System(11988): Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from version 95 to 94
07-20 07:13:42.114: E/System(11988): at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:361)
07-20 07:13:42.114: E/System(11988): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:255)
07-20 07:13:42.114: E/System(11988): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
07-20 07:13:42.114: E/System(11988): at com.android.providers.settings.SettingsProvider.establishDbTracking(SettingsProvider.java:386)
07-20 07:13:42.114: E/System(11988): at com.android.providers.settings.SettingsProvider.onCreate(SettingsProvider.java:326)
07-20 07:13:42.114: E/System(11988): at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
07-20 07:13:42.114: E/System(11988): at android.app.ActivityThread.installProvider(ActivityThread.java:4817)
07-20 07:13:42.114: E/System(11988): ... 4 more
07-20 07:13:42.114: I/SystemServer(11988): Input Method Service
07-20 07:13:42.454: W/InputMethodManagerService(11988): Couldn't create dir.: /data/system/inputmethod
07-20 07:13:42.626: D/ActivityThread(11988): Loading provider settings: com.android.providers.settings.SettingsProvider
07-20 07:13:43.634: W/SystemServer(11988): ***********************************************
07-20 07:13:43.666: A/SystemServer(11988): BOOT FAILURE starting Input Manager Service
07-20 07:13:43.666: A/SystemServer(11988): java.lang.RuntimeException: Unable to get provider com.android.providers.settings.SettingsProvider: android.database.sqlite.SQLiteException: Can't downgrade database from version 95 to 94
07-20 07:13:43.666: A/SystemServer(11988): at android.app.ActivityThread.installProvider(ActivityThread.java:4820)
07-20 07:13:43.666: A/SystemServer(11988): at android.app.ActivityThread.acquireProvider(ActivityThread.java:4471)
07-20 07:13:43.666: A/SystemServer(11988): at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1987)
07-20 07:13:43.666: A/SystemServer(11988): at android.content.ContentResolver.acquireProvider(ContentResolver.java:1085)
07-20 07:13:43.666: A/SystemServer(11988): at android.provider.Settings$NameValueCache.lazyGetProvider(Settings.java:749)
07-20 07:13:43.666: A/SystemServer(11988): at android.provider.Settings$NameValueCache.getStringForUser(Settings.java:796)
07-20 07:13:43.666: A/SystemServer(11988): at android.provider.Settings$Secure.getStringForUser(Settings.java:2757)
07-20 07:13:43.666: A/SystemServer(11988): at com.android.server.InputMethodManagerService$InputMethodSettings.getSelectedInputMethod(InputMethodManagerService.java:3832)
07-20 07:13:43.666: A/SystemServer(11988): at com.android.server.InputMethodManagerService.<init>(InputMethodManagerService.java:669)
07-20 07:13:43.666: A/SystemServer(11988): at com.android.server.ServerThread.run(SystemServer.java:361)
07-20 07:13:43.666: A/SystemServer(11988): Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from version 95 to 94
07-20 07:13:43.666: A/SystemServer(11988): at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:361)
07-20 07:13:43.666: A/SystemServer(11988): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:255)
07-20 07:13:43.666: A/SystemServer(11988): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
07-20 07:13:43.666: A/SystemServer(11988): at com.android.providers.settings.SettingsProvider.establishDbTracking(SettingsProvider.java:386)
07-20 07:13:43.666: A/SystemServer(11988): at com.android.providers.settings.SettingsProvider.onCreate(SettingsProvider.java:326)
07-20 07:13:43.666: A/SystemServer(11988): at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
07-20 07:13:43.666: A/SystemServer(11988): at android.app.ActivityThread.installProvider(ActivityThread.java:4817)
07-20 07:13:43.666: A/SystemServer(11988): ... 9 more
07-20 07:13:43.866: I/SystemServer(11988): Accessibility Manager
07-20 07:13:44.056: W/SystemServer(11988): ***********************************************
07-20 07:13:44.056: A/SystemServer(11988): BOOT FAILURE making display ready
07-20 07:13:44.056: A/SystemServer(11988): java.lang.NullPointerException
07-20 07:13:44.056: A/SystemServer(11988): at com.android.server.ServerThread.run(SystemServer.java:377)
07-20 07:13:44.095: W/dalvikvm(11988): threadid=11: thread exiting with uncaught exception (group=0xb5e2f908)
07-20 07:13:44.095: E/AndroidRuntime(11988): *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
07-20 07:13:44.095: E/AndroidRuntime(11988): java.lang.NullPointerException
07-20 07:13:44.095: E/AndroidRuntime(11988): at com.android.server.am.ActivityManagerService.showBootMessage(ActivityManagerService.java:4353)
07-20 07:13:44.095: E/AndroidRuntime(11988): at com.android.server.ServerThread.run(SystemServer.java:389)
这是我的清单文件清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.searchdb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.searchdb.MainActivity"
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>
这是我的主要活动课程:主要活动:
package com.example.searchdb;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class MainActivity extends Activity {
protected EditText searchText;
protected SQLiteDatabase db;
protected Cursor cursor;
protected ListAdapter adapter;
protected ListView employeeList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = (new DatabaseHelper(this)).getWritableDatabase();
searchText = (EditText) findViewById (R.id.searchText);
employeeList = (ListView) findViewById (R.id.list);
}
@SuppressWarnings("deprecation")
public void search(View view) {
// || is the concatenation operation in SQLite
cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE firstName || ' ' || lastName LIKE ?",
new String[]{"%" + searchText.getText().toString() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.list_item,
cursor,
new String[] {"firstName", "lastName", "title"},
new int[] {R.id.firstName, R.id.lastName, R.id.title});
employeeList.setAdapter(adapter);
}
}
这是另一个使用 sqlite 数据库的类:DatabaseHelper.java:
package com.example.searchdb;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "employee_directory";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
/*
* Create the employee table and populate it with sample data.
* In step 6, we will move these hardcoded statements to an XML document.
*/
String sql = "CREATE TABLE IF NOT EXISTS employee (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstName TEXT, " +
"lastName TEXT, " +
"title TEXT, " +
"officePhone TEXT, " +
"cellPhone TEXT, " +
"email TEXT, " +
"managerId INTEGER)";
db.execSQL(sql);
ContentValues values = new ContentValues();
values.put("firstName", "John");
values.put("lastName", "Smith");
values.put("title", "CEO");
values.put("officePhone", "617-219-2001");
values.put("cellPhone", "617-456-7890");
values.put("email", "jsmith@email.com");
db.insert("employee", "lastName", values);
values.put("firstName", "Robert");
values.put("lastName", "Jackson");
values.put("title", "VP Engineering");
values.put("officePhone", "617-219-3333");
values.put("cellPhone", "781-444-2222");
values.put("email", "rjackson@email.com");
values.put("managerId", "1");
db.insert("employee", "lastName", values);
values.put("firstName", "Marie");
values.put("lastName", "Potter");
values.put("title", "VP Sales");
values.put("officePhone", "617-219-2002");
values.put("cellPhone", "987-654-3210");
values.put("email", "mpotter@email.com");
values.put("managerId", "1");
db.insert("employee", "lastName", values);
values.put("firstName", "Lisa");
values.put("lastName", "Jordan");
values.put("title", "VP Marketing");
values.put("officePhone", "617-219-2003");
values.put("cellPhone", "987-654-7777");
values.put("email", "ljordan@email.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
values.put("firstName", "Christophe");
values.put("lastName", "Coenraets");
values.put("title", "Evangelist");
values.put("officePhone", "617-219-0000");
values.put("cellPhone", "617-666-7777");
values.put("email", "ccoenrae@adobe.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
values.put("firstName", "Paula");
values.put("lastName", "Brown");
values.put("title", "Director Engineering");
values.put("officePhone", "617-612-0987");
values.put("cellPhone", "617-123-9876");
values.put("email", "pbrown@email.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
values.put("firstName", "Mark");
values.put("lastName", "Taylor");
values.put("title", "Lead Architect");
values.put("officePhone", "617-444-1122");
values.put("cellPhone", "617-555-3344");
values.put("email", "mtaylor@email.com");
values.put("managerId", "2");
db.insert("employee", "lastName", values);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS employees");
onCreate(db);
}
}