SQLite没有读取数据输入

时间:2016-09-21 16:49:28

标签: android android-sqlite

当我运行Register Java Class并在系统中输入我的数据时,数据库没有保存或创建。是什么给了我这个错误?

这是我在创建SQLite表查询的java类。

public class ListBaseHelper extends SQLiteOpenHelper {

    private static final String TAG = "ListBaseHelper";
    private static final int VERSION = 2;
    private static final String DATABASE_NAME = "listBase.db";
    //DEfine a query for creating table so you don't get lost
    private static final String CREATE_QUERY =
            "CREATE TABLE " + ListDbSchema.ListTable.Cols.UUID+"(" + ListDbSchema.ListTable.Cols.NAME+" TEXT,"+
                    ListDbSchema.ListTable.Cols.AGE+ " TEXT," + ListDbSchema.ListTable.Cols.DATE+ "TEXT"+
                    ListDbSchema.ListTable.Cols.ACTIVE + "TEXT);";

    public ListBaseHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
        //Log message
        Log.e("DATABASE OPERATIONS", "Database created /opened...");
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_QUERY);
        Log.e("DATABASE OPERATIONS", "Table created...");
    }

    public void addInformations(String uuid, String name, String age, SQLiteDatabase db) {

        ContentValues contentValues = new ContentValues();
        contentValues.put(ListDbSchema.ListTable.Cols.UUID, uuid);
        contentValues.put(ListDbSchema.ListTable.Cols.NAME, name);
        contentValues.put(ListDbSchema.ListTable.Cols.AGE, age);
        db.insert(ListDbSchema.ListTable.Cols.AGE, null, contentValues);
        Log.e("DATABASE OPERATIONS", "One row inserted...");

    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}

包含数据库列的另一个java类。

public class ListDbSchema {

    public static final class ListTable {

        //Table column names
        public static final class Cols {
            public static final String UUID = "uuid";
            public static final String NAME = "name";
            public static final String AGE = "age";
            public static final String DATE = "date";
            public static final String ACTIVE = "active";
        }
    }
}

注册用户将输入数据的Java类

public class RegisterActivity extends AppCompatActivity {

    Button btn_register_new_user;
    EditText ContactName, ContactAge, ContactDate;
    Context context = this;
    ListBaseHelper listbasehelper;
    SQLiteDatabase sqliteDatabase;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        ContactName = (EditText) findViewById(R.id.register_name);
        ContactAge = (EditText) findViewById(R.id.register_age);
        ContactDate = (EditText) findViewById(R.id.register_date);

        btn_register_new_user = (Button)findViewById(R.id.register_new_user);
        btn_register_new_user.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                //Use the name of this class, and the name class where you want to be taken when the button is clicked.
                Intent intent = new Intent(RegisterActivity.this, UserAccountActivity.class);
                startActivity(intent);


            }
        });    
    }

    public void addContact (View view)
    {
    String name = ContactName.getText().toString();
    String age = ContactAge.getText().toString();
    String date = ContactDate.getText().toString();

    listbasehelper = new ListBaseHelper(context);
    sqliteDatabase = listbasehelper.getWritableDatabase();
    listbasehelper.addInformations(name, age, date, sqliteDatabase);
    Toast.makeText(getBaseContext(), "Data Saved", Toast.LENGTH_LONG).show();
        listbasehelper.close();
    }

}

这是LogCat消息 E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system

0 个答案:

没有答案