我可以運行我的應用程序高達Android 5.1.1。但不能進入主頁到Android 6(DB創建和數據可以在這裏插入),應用程序在這裏強行停止工作。我無法在棉花糖運行我的應用程序。我該如何解決這個問題?
以上Android 6 DB沒有創建。任何一個可以提供一個解決方案...
DBHelper類
public class DatabaseHelper extends SQLiteOpenHelper{
private static final String DatabaseName="/mnt/sdcard/Hmeauto1_DB.db";
private static final int DatabaseVersion=1;
SQLiteDatabase db;
public String c=null;
public static final String Query = "CREATE TABLE " + UserConstruct.newUserinfo.TableName + " (" + UserConstruct.newUserinfo.Id + " INTEGER PRIMARY KEY AUTOINCREMENT, " + UserConstruct.newUserinfo.UserName + " TEXT, " + UserConstruct.newUserinfo.Password + " TEXT," + UserConstruct.newUserinfo.FName + " TEXT, " + UserConstruct.newUserinfo.LName + " TEXT," + UserConstruct.newUserinfo.ACode + " TEXT," + UserConstruct.newUserinfo.AEmail + " TEXT, " + UserConstruct.newUserinfo.User_Type + " TEXT);";
public static final String Query1 = "CREATE TABLE " + UserConstruct.add_home.TableName + " (" + UserConstruct.add_home.Home_Id + " INTEGER PRIMARY KEY AUTOINCREMENT, " + UserConstruct.add_home.Home_Name + " TEXT, " + UserConstruct.add_home.Home_Number + " INTEGER, " + UserConstruct.add_home.UserName + " TEXT);";
public static final String Query2 = "CREATE TABLE " + UserConstruct.add_Floors.TableName + " (" + UserConstruct.add_Floors.Flr_Id + " INTEGER PRIMARY KEY AUTOINCREMENT, " + UserConstruct.add_Floors.Home_Id + " INTEGER, " + UserConstruct.add_Floors.Flr_Name + " TEXT, " + UserConstruct.add_Floors.Flr_Number + " INTEGER, " + UserConstruct.add_Floors.UserName + " TEXT ;";
public static final String Query3 = "CREATE TABLE " + UserConstruct.add_Rooms.TableName + " (" + UserConstruct.add_Rooms.Room_Id + " INTEGER PRIMARY KEY AUTOINCREMENT, " + UserConstruct.add_Rooms.Flr_Id + " INTEGER, " + UserConstruct.add_Rooms.Home_Id + " INTEGER, " + UserConstruct.add_Rooms.Room_Name + " TEXT, " + UserConstruct.add_Rooms.Room_Number + " INTEGER, " + UserConstruct.add_Rooms.UserName + " TEXT ;";
// public static final String Floor="CREATE TABLE "+UserConstruct.Floors.TableName+" ("+UserConstruct.Floors.Flr_Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "+UserConstruct.Floors.Flr_Name+" TEXT);";
public static final String Query4 = "CREATE TABLE " + UserConstruct.image_list.TableName + " (" + UserConstruct.image_list.Id + " INTEGER PRIMARY KEY AUTOINCREMENT, " + UserConstruct.image_list.Image_Name_fxd + " TEXT, " + UserConstruct.image_list.Image_Name + " TEXT, " + UserConstruct.image_list.Device_ID + " TEXT, " + UserConstruct.image_list.Home_Id + " INTEGER, " + UserConstruct.image_list.Flr_Id + " INTEGER, " + UserConstruct.image_list.Room_Id + " INTEGER, " + UserConstruct.image_list.UserName + " TEXT);";
public DatabaseHelper(Context context)
{
super(context, DatabaseName, null, DatabaseVersion);
Log.e("Database operation", "created or opened";
// Log.d("path:", String.valueOf(context.getDatabasePath(DatabaseName)));
}
@Override
public void onCreate (SQLiteDatabase db)
{
try {
db.execSQL(Query);
Log.e("Created", "User Table Created";
db.execSQL(Query1);
Log.e("Created", "Add Home Table Created";
db.execSQL(Query2);
Log.e("Created", "Add Floor Table Created";
db.execSQL(Query3);
Log.e("Created", "Add Room Table Created";
db.execSQL(Query4);
Log.e("Created", "Add Room Table Created";
}catch (RuntimeException e){e.printStackTrace();}
}
@Override
public void onUpgrade (SQLiteDatabase db,int oldVersion, int newVersion)
{
try {
String query = "DROP TABLE IF EXIST" + UserConstruct.newUserinfo.TableName;
db.execSQL(query);
String query1 = "DROP TABLE IF EXIST" + UserConstruct.add_Rooms.TableName;
db.execSQL(query1);
String query2 = "DROP TABLE IF EXIST" + UserConstruct.add_Floors.TableName;
db.execSQL(query2);
String query3 = "DROP TABLE IF EXIST" + UserConstruct.add_home.TableName;
db.execSQL(query3);
String query4 = "DROP TABLE IF EXIST" + UserConstruct.image_list.TableName;
db.execSQL(query4);
}catch(RuntimeException e){e.printStackTrace();}
// this.db=db;
}
public void insert(String Fname, String Lname, String Aemail, String Acode, String userName, String Password, String userType, SQLiteDatabase db) {
ContentValues contentvalue = new ContentValues();
contentvalue.put(UserConstruct.newUserinfo.FName, Fname);
contentvalue.put(UserConstruct.newUserinfo.LName, Lname);
contentvalue.put(UserConstruct.newUserinfo.AEmail, Aemail);
contentvalue.put(UserConstruct.newUserinfo.ACode, Acode);
contentvalue.put(UserConstruct.newUserinfo.UserName, userName);
contentvalue.put(UserConstruct.newUserinfo.Password, Password);
contentvalue.put(UserConstruct.newUserinfo.User_Type, userType);
db.insert(UserConstruct.newUserinfo.TableName, null, contentvalue);
Log.e("Insertion", "One row inserted";
db.close();
}
註冊數據
View.OnClickListener adduserOnClickListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
fname=(EditText)findViewById(R.id.editTextFname);
sname=(EditText)findViewById(R.id.editTextsname);
email=(EditText)findViewById(R.id.editTextEmail);
code=(EditText)findViewById(R.id.editTextcode);
Uname=(EditText)findViewById(R.id.editTextuser);
pwrd=(EditText)findViewById(R.id.editTextpass);
//utype=(Spinner)findViewById(R.id.spinnerutype);
String fname1 = fname.getText().toString();
String lname1 = sname.getText().toString();
String email1 = email.getText().toString();
String code1 = code.getText().toString();
String uname1 = Uname.getText().toString();
String pswd1 = pwrd.getText().toString();
String utype1 = "admin";
if (fname1.equals("") {
Toast.makeText(getBaseContext(), "Enter First Name", Toast.LENGTH_LONG).show();
} else if (lname1.equals("") {
Toast.makeText(getBaseContext(), "Enter Second Name", Toast.LENGTH_LONG).show();
} else if (email1.equals("") {
Toast.makeText(getBaseContext(), "Enter Email Id ", Toast.LENGTH_LONG).show();
} else if (code1.equals("") {
Toast.makeText(getBaseContext(), "Enter Authentication Code ", Toast.LENGTH_LONG).show();
} else if (uname1.equals("") {
Toast.makeText(getBaseContext(), "Enter User Name", Toast.LENGTH_LONG).show();
} else if (pswd1.equals("") {
Toast.makeText(getBaseContext(), "Enter Password ", Toast.LENGTH_LONG).show();
}else {
try {
sqlitedatabase = openOrCreateDatabase(DatabaseName, Context.MODE_PRIVATE, null);
Cursor allrows19 = sqlitedatabase.rawQuery("SELECT * FROM " + UserConstruct.newUserinfo.TableName + " WHERE " + UserConstruct.newUserinfo.UserName + "=='" + uname1 + "'", null);
if (allrows19.getCount() <= 0) {
// Toast.makeText(getBaseContext(), "Not exist", Toast.LENGTH_LONG).show();
exist = false;
} else if (allrows19.getCount() < 1) {
exist = false;
// Toast.makeText(getBaseContext(), "Not exist", Toast.LENGTH_LONG).show();
}
allrows19.close();
dbhelper.close();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "",
Toast.LENGTH_LONG);
}
if (exist) {
Toast.makeText(getBaseContext(), "This User Name not available", Toast.LENGTH_LONG).show();
}
else
{
dbhelper = new DatabaseHelper(context);
sqlitedatabase = dbhelper.getWritableDatabase();
dbhelper.insert(fname1, lname1, email1, code1, uname1, pswd1, utype1, sqlitedatabase);
Toast.makeText(getBaseContext(), "Data inserted", Toast.LENGTH_LONG).show();
dbhelper.close();
Registration.this.finish();
Intent intent=new Intent(Registration.this,LoginActivity.class);
startActivity(intent);
}
}
// }
}catch (NullPointerException e){e.printStackTrace();}
}
};
把你堆棧垃圾 –
上午在Android ..堆棧垃圾手段? – Sjn
我猜它是因爲權限。你必須請求在數據庫寫入數據庫到運行時的棉花糖的權限 –