我是Android App开发的新手。我正在学习Sqlite并遇到问题。 我正在尝试使用Room从SQLite数据库检索数据,并发现“数据库打开失败”错误。日志说:
2018-10-30 11:30:18.261 2615-2629/? E/JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
java.lang.RuntimeException: database open failed
at com.cleanmaster.provider.DatebaseProvider.a(DatebaseProvider.java:357)
at com.cleanmaster.provider.DatebaseProvider.query(DatebaseProvider.java:297)
at android.content.ContentProvider.query(ContentProvider.java:1028)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
at android.os.Binder.execTransact(Binder.java:567)
我的AppDatabase.class
package com.impresscapital.iclapp.database;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverter;
import android.arch.persistence.room.TypeConverters;
import android.content.Context;
import android.util.Log;
import com.impresscapital.iclapp.dao.UserDao;
import com.impresscapital.iclapp.dbobj.User;
import com.impresscapital.iclapp.util.DateConverter;
@Database(entities = {User.class},version = 1, exportSchema = false)
@TypeConverters({DateConverter.class})
public abstract class AppDatabase extends RoomDatabase {
private static final String LOG_CAT=AppDatabase.class.getSimpleName();
private static final Object LOCK=new Object();
private static final String DATABASE_NAME="db_icl_app";
private static AppDatabase sInstance;
public static AppDatabase getInstance(Context context){
if(sInstance==null){
synchronized (LOCK){
Log.d(LOG_CAT,"Creating new Database");
sInstance=Room.databaseBuilder(context.getApplicationContext(),
AppDatabase.class,AppDatabase.DATABASE_NAME).build();
}
}
Log.d(LOG_CAT,"Getting the database instance");
return sInstance;
}
public abstract UserDao userDao();
}
我要从中访问数据库的类是UserSigninAuthentication.class。这是代码
package com.impresscapital.iclapp.util;
import android.content.Context;
import android.util.Log;
import com.impresscapital.iclapp.database.AppDatabase;
import com.impresscapital.iclapp.database.AppExecutors;
import com.impresscapital.iclapp.dbobj.User;
import java.util.List;
public class UserSigninAuthentication {
private Boolean isAuthenticate=false;
public boolean authenticate(final String username, final String password, Context context, final AppDatabase mDb){
AppExecutors.getsInstance().getDiskIO().execute(new Runnable() {
@Override
public void run() {
List<User> user=mDb.userDao().loadUser(username,password);
if(user.size()==1){
isAuthenticate=true;
}
Log.d("IsAuthenticate Value",isAuthenticate.toString());
}
});
return isAuthenticate;
}
}
UserDao.class
package com.impresscapital.iclapp.dao;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import com.impresscapital.iclapp.dbobj.User;
import java.util.List;
@Dao
public interface UserDao {
@Query("Select * from user_table where username like :inputUserame and password like :inputPassword LIMIT 1")
List<User> loadUser(String inputUserame,String inputPassword);
@Query("Select * from user_table")
List<User> retrieveAllUser();
@Insert
void registerUser(User user);
@Update
void updateUser(User user);
@Delete
void deleteUser(User user);
}
AppExecutors.getsInstance().getDiskIO().execute(new Runnable() {..
感谢您提前帮助我。