だから私はSQLに非常に慣れていません。xml ファイルを取得して、検索可能なデータベースにしようとしています。構文エラーがありますが、表示できません/表示するのに十分な知識がありません。これが私のonCreateメソッドです
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);
}
createData()
private void createDate() {
PullParser parser = new PullParser();
List<Stops> stops = parser.parseXML(this);
for ( Stops stop: stops) {
dataSource.create(stop);
}
}
そしてDBヘルパー
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);
}
}
私が得ているエラーは
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
TABLE_CREATE に問題があり、明らかに問題はありません。助言がありますか?前もって感謝します。