gpt4 book ai didi

java - 安卓教程错误

转载 作者:太空狗 更新时间:2023-10-29 13:35:20 25 4
gpt4 key购买 nike

我从 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);
}
}
}

还有更多,但我正在努力简化。

我收到以下错误:

Description Resource Path Location Type

Syntax error on token ")", { expected after this token DBAdapter.java

onUpgrade 结束

Syntax error, insert "}" to complete ClassBody DBAdapter.java

Syntax error, insert "}" to complete ClassBody DBAdapter.java

onCreate 结束时

我是 Android 应用的新手,有人可以帮助我理解这些消息吗?

这是 Eclipse 显示的内容:

enter image description here

最佳答案

这些是来自编译器的消息,告诉您大括号 {} 和/或圆括号 () 在文件中不平衡。如果您复制/粘贴了此代码,请确保您没有遗漏末尾的大括号或类似内容。您发布的代码看起来很平衡,因此它必须在文件中更靠后的位置。

HTH

关于java - 安卓教程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11191918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com