Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android tutorial errors

Tags:

java

android

I've borrowed the following code from Wei-Meng Lee's "Beginning Android Application Development":

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

There's more but I'm trying to simplify.

I get the following errors:

Description Resource Path Location Type

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

at the end of onUpgrade

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

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

at the end of onCreate

I'm new to Android apps so could somebody please help me understand these messages?

Here's what Eclipse is displaying:

enter image description here

like image 872
John Avatar asked May 30 '26 03:05

John


1 Answers

Those are messages from the compiler telling you that your braces {} and/or parentheses () are unbalanced in the file. If you copied/pasted this code, make sure you didn't miss a brace at the end or something like that. The code that you've posted looks balanced, so it must be further down in the file.

HTH

like image 84
devunwired Avatar answered Jun 01 '26 18:06

devunwired