Eclipse编译错误

时间:2014-06-18 20:37:48

标签: java android sqlite

我有以下代码将sqlite数据库连接到Android应用程序,而public class TestAdapter不起作用。当我编译应用程序时,我收到以下错误:

The public type TestAdapter must be definied "

我的代码

import java.io.IOException;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class TestAdapter 
{
protected static final String TAG = "DataAdapter";

private final Context mContext;
private SQLiteDatabase mDb;
private DataBaseHelper mDbHelper;

public TestAdapter(Context context) 
{
    this.mContext = context;
    mDbHelper = new DataBaseHelper(mContext);
}

public TestAdapter createDatabase() throws SQLException 
{
    try 
    {
        mDbHelper.createDataBase();
    } 
    catch (IOException mIOException) 
    {
        Log.e(TAG, mIOException.toString() + "  UnableToCreateDatabase");
        throw new Error("UnableToCreateDatabase");
    }
    return this;
}

public TestAdapter open() throws SQLException 
{
    try 
    {
        mDbHelper.openDataBase();
        mDbHelper.close();
        mDb = mDbHelper.getReadableDatabase();
    } 
    catch (SQLException mSQLException) 
    {
        Log.e(TAG, "open >>"+ mSQLException.toString());
        throw mSQLException;
    }
    return this;
}

public void close() 
{
    mDbHelper.close();
}

 public Cursor getTestData()
 {
     try
     {
         String sql ="SELECT * FROM myTable";

         Cursor mCur = mDb.rawQuery(sql, null);
         if (mCur!=null)
         {
            mCur.moveToNext();
         }
         return mCur;
     }
     catch (SQLException mSQLException) 
     {
         Log.e(TAG, "getTestData >>"+ mSQLException.toString());
         throw mSQLException;
     }
 }
 }

public class DataAdapter {

}

我该怎么办?谢谢!

1 个答案:

答案 0 :(得分:0)

中删除public
public class DataAdapter {

}