SQLite数据库文件中有一个错误,请告诉我如何纠正它

时间:2015-05-20 06:20:51

标签: java android sqlite

当我运行时SQLite数据库文件中出现错误此项目应用程序被强制关闭并在行号36中指出错误请告诉我如何纠正它.....         在此处输入代码         包com.flocater;

    import com.flocator.R;`enter code here`
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.telephony.TelephonyManager;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;



    public class Friendfinderactivity extends Activity {
        /** C`

    `alled when the activity is first created. */
        String deviceid = "";


        String device_id = "";
        String user_id = "";

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            DBHelper dbhelper = new DBHelper(this);
            SQLiteDatabase db = dbhelper.getWritableDatabase();

            TelephonyManager tm = (TelephonyManager) this
                    .getSystemService(Context.TELEPHONY_SERVICE);

            deviceid = tm.getDeviceId();

            Cursor cursor = db.rawQuery("select * from"
                    + DBHelper.SUBSCRIBE_TABLE_NAME, null);

            int rows = cursor.getCount();

            if (rows > 0) {
                cursor.moveToFirst();
                user_id = cursor.getString(0);
                device_id = cursor.getString(3);
            }
            db.close();
            if (device_id.equals(deviceid)) {
                setContentView(R.layout.subscriber);
            } else
                setContentView(R.layout.subscribe);
        }

        public void subscribeUser(View v) {
            // get access to views
            EditText editName = (EditText) this.findViewById(R.id.editName);
            EditText editPhone = (EditText) this.findViewById(R.id.editPhone);
            EditText editArea = (EditText) this.findViewById(R.id.editArea);
            EditText editCity = (EditText) this.findViewById(R.id.editCity);

            boolean done = DBHelper.AddFriends(this, editName.getText().toString(),
                    editPhone.getText().toString(), deviceid, editArea.getText()
                            .toString(), editCity.getText().toString());

            if(done) {
                Toast.makeText(this, "Subscribed Successfully!", Toast.LENGTH_LONG).show();
                Intent intent = new Intent(this,Friendfinderactivity.class);
                startActivity(intent);
            }
            else
                Toast.makeText(this, "Sorry! Could not subscribe!", Toast.LENGTH_LONG).show();
        }

        public void addFriends(View v) {
            Intent intent = new Intent(this,AddFriends.class);
            startActivity(intent);
        }

        public void viewFriends(View v) {
            Intent intent = new Intent(this,SeeFriends.class);
            startActivity(intent);
        }

        public void seeLocation(View v) {
            Intent intent = new Intent(this,SeeFriends.class);
            startActivity(intent);
        }

        public void updateDetails(View v) {
            Intent intent = new Intent(this,UpdateFriends.class);
            intent.putExtra("userid", user_id);
            startActivity(intent);
        }
    }

ERROR MESSAGE :
05-20 02:04:45.380: E/SQLiteLog(1851): (1) near "fromnull": syntax error
05-20 02:04:45.381: E/AndroidRuntime(1851): FATAL EXCEPTION: main
05-20 02:04:45.381: E/AndroidRuntime(1851): Process: com.flocator, PID: 1851
05-20 02:04:45.381: E/AndroidRuntime(1851): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flocator/com.flocater.Friendfinderactivity}: android.database.sqlite.SQLiteException: near "fromnull": syntax error (code 1): , while compiling: select * fromnull
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.os.Handler.dispatchMessage(Handler.java:102)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.os.Looper.loop(Looper.java:135)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.ActivityThread.main(ActivityThread.java:5221)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at java.lang.reflect.Method.invoke(Native Method)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at java.lang.reflect.Method.invoke(Method.java:372)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
05-20 02:04:45.381: E/AndroidRuntime(1851): Caused by: android.database.sqlite.SQLiteException: near "fromnull": syntax error (code 1): , while compiling: select * fromnull
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at com.flocater.Friendfinderactivity.onCreate(Friendfinderactivity.java:37)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.Activity.performCreate(Activity.java:5933)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
05-20 02:04:45.381: E/AndroidRuntime(1851):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
05-20 02:04:45.381: E/AndroidRuntime(1851):     ... 10 more

1 个答案:

答案 0 :(得分:3)

Cursor cursor = db.rawQuery("select * from"
                    + DBHelper.SUBSCRIBE_TABLE_NAME, null);

问题1:在&#34;

后面添加一个空格

问题2:您的DBHelper.SUBSCRIBE_TABLE_NAME似乎已解除​​为空