0

So I'm very new to SQL. I'm trying to take a xml file to make it into a database that I can search. I have a syntax error but can't see it/not familiar enough to see it. Here is my onCreate method

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    sPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    sContext = getApplicationContext();
    boolean boot = settings.getBoolean("launch", false);
    if (boot == false) {
        createData();
    }
    dataSource = new StopsDataSource(this);
    dbhelper = new StopsDBHelper(this,"stops",null,1);
    mDatabase = dbhelper.getWritableDatabase();
    dataSource.open();
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        //Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
    }else{
        showGPSDisabledAlertToUser();
    }
    //MyLocationListener = new MyLocationListener();



    notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}

The creatData()

 private void createDate() {
    PullParser parser = new PullParser();
    List<Stops> stops = parser.parseXML(this);

    for ( Stops stop: stops) {
        dataSource.create(stop);
    }
}

And the DBHelper

public class StopsDBHelper extends SQLiteOpenHelper {

public static final String TABLE_STOPS = "stops";
public static final String COlUMN_ID = "stopID";
public static final String COLUMN_STOP_NAME = "stopName";
public static final String COLUMN_STOP_LAT = "stopLat";
public static final String COLUMN_STOP_LON = "stopLon";
public static final String TABLE_CREATE = "CREATE TABLE" + TABLE_STOPS + "(" + COlUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +  COlUMN_ID + " TEXT, " + COLUMN_STOP_LAT + " TEXT, "
        + COLUMN_STOP_LON + " TEXT, " + COLUMN_STOP_NAME + " TEXT" + ")";
public StopsDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    sqLiteDatabase.execSQL(TABLE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_STOPS);
    onCreate(sqLiteDatabase);
}

}

The error I'm getting is

   08-06 19:21:06.041    5784-5784/ccalgary.transit.helper E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{ccalgary.transit.helper/ccalgary.transit.helper.MainActivity}: android.database.sqlite.SQLiteException: near "TABLEstops": syntax error (code 1): , while compiling: CREATE TABLEstops(stopID INTEGER PRIMARY KEY AUTOINCREMENT, stopID TEXT, stopLat TEXT, stopLon TEXT, stopName TEXT)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
        at android.app.ActivityThread.access$600(ActivityThread.java:150)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5195)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.database.sqlite.SQLiteException: near "TABLEstops": syntax error (code 1): , while compiling: CREATE TABLEstops(stopID INTEGER PRIMARY KEY AUTOINCREMENT, stopID TEXT, stopLat TEXT, stopLon TEXT, stopName TEXT)
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
        at ccalgary.transit.helper.StopsDBHelper.onCreate(StopsDBHelper.java:25)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
        at ccalgary.transit.helper.MainActivity.onCreate(MainActivity.java:75)
        at android.app.Activity.performCreate(Activity.java:5104)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
        ... 11 more

It's having issues with the TABLE_CREATE and I can't see anything obviously wrong with it. Any suggestions? Thanks in advance.

2 Answers 2

1

Yup, you do have syntax error here. Change this line

public static final String TABLE_CREATE = "CREATE TABLE" + TABLE_STOPS + "(" + COlUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +  COlUMN_ID + " TEXT, " + COLUMN_STOP_LAT + " TEXT, "
    + COLUMN_STOP_LON + " TEXT, " + COLUMN_STOP_NAME + " TEXT" + ")";

To this:

public static final String TABLE_CREATE = "CREATE TABLE " + TABLE_STOPS + "(" + COlUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +  COlUMN_ID + " TEXT, " + COLUMN_STOP_LAT + " TEXT, "
    + COLUMN_STOP_LON + " TEXT, " + COLUMN_STOP_NAME + " TEXT" + ")";

You are just missing a space between TABLE and TableName in your query

Sign up to request clarification or add additional context in comments.

3 Comments

Much nicer answer than mine
Yea, it used to happen to me all the time in the beginning, thats how you learn, can you mark the answer correct if it solved your problem
yup, It was just making me wait so long before it would let me choose the answer
0

There is no space between TABLE and stops. That will most likely fix it. You need to CREATE TABLE stop not CREATE TABLEstop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.