我已经借了魏萌李的“开头的Android应用开发”下面的代码: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
语法错误,插入 “}” 在
onCreate
末我是新来的Android完成ClassBody DBAdapter.java
的应用,因此可能有人请帮助我理解这些消息?
这里是Eclipse是显示:
你试过插入“}”吗? –
它看起来十字是灰色的,所以错误被删除?尝试清洁,并建立 –
我需要点击保存按钮来更新我所有的faffing编辑! – John