我正在尝试从服务器解析A JSON,并将解析后的对象解析为android上的SQLite。
SQLHandler.java
public class SQLiteHandler extends SQLiteOpenHelper {
private static final String TAG = SQLiteHandler.class.getSimpleName();
public SQLiteHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Create Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USER + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
+ KEY_EMAIL + " TEXT UNIQUE," + KEY_UID + " TEXT,"
+ KEY_CREATED_AT + " TEXT" + ")";
String CREATE_ZONE_TABLE = "CREATE TABLE " + TABLE_ZONES + "("
+ KEY_ZONE_ID + " INTEGER," + KEY_ZONE_NAME + " TEXT" + ")";
db.execSQL(CREATE_ZONE_TABLE);
db.execSQL(CREATE_LOGIN_TABLE);
}
它应该自动创建区域表,但它不会。运行应用程序时,我遇到区域表不存在的错误。我从onCreateView的片段活动中调用SQLHandler。为什么它不创建表? (我从onCreate方法调用SQLhandler之后,从我的另一个应用程序中获取了代码,其中创建了表)
SendDataFragment.java:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
db = new SQLiteHandler(getActivity().getApplicationContext());
// db.deleteZones();
ZonesArray = new ArrayList<>();
new GetZones().execute();
FrameLayout rootView = (FrameLayout) inflater.inflate(R.layout.fragment_send, container, false);
...
答案 0 :(得分:0)
卸载应用程序并再次运行它的一个小建议。