我从 Wei-Meng Lee 的“开始 Android 应用程序开发”中借用了以下代码:
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "MyDB";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
"create table contacts (_id integer primary key autoincrement, "
+ "name text not null, email text not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter (Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(DATABASE_CREATE);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
}
}
还有更多,但我试图简化。
我收到以下错误:
说明 资源路径 位置 类型
令牌 ")" 上的语法错误,{ 在此令牌 DBAdapter.java 之后预期
在......的最后onUpgrade
语法错误,插入“}”完成ClassBody DBAdapter.java
语法错误,插入“}”完成ClassBody DBAdapter.java
在......的最后onCreate
我是 Android 应用程序的新手,所以有人可以帮我理解这些消息吗?
这是 Eclipse 显示的内容: