Click here to Skip to main content
15,851,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My App crachs in some devices with error :
ERROR : MM-DD HH:MM:SS   8379 8379 E  libc : access denied finding property "re.vendor.pref_scale_resolution"


I tried find to find what causes this error and i find it causes by SQLite database and Here is my DB_Helper class :
public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "pms.db";
private static final String DATABASE_PATH = "/data/data/com.pms.app/databases/";

public DatabaseHelper(@Nullable Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		this.context = context;
		createDb();
	}

//

public void createDb(){
		boolean dbExist = checkDbExist();
		
		if(!dbExist){
			this.getReadableDatabase();
			copyDatabase();
		}
	}
	
	private boolean checkDbExist(){
		SQLiteDatabase sqLiteDatabase = null;
		
		try{
			String path = DATABASE_PATH + DATABASE_NAME;
			sqLiteDatabase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
			} catch (Exception ex){
		}
		
		if(sqLiteDatabase != null){
			sqLiteDatabase.close();
			return true;
		}
		
		return false;
	}
	
	private void copyDatabase(){
		try {
			InputStream inputStream = context.getAssets().open(DATABASE_NAME);
			
			String outFileName = DATABASE_PATH + DATABASE_NAME;
			
			OutputStream outputStream = new FileOutputStream(outFileName);
			
			byte[] b = new byte[1024];
			int length;
			
			while ((length = inputStream.read(b)) > 0){
				outputStream.write(b, 0, length);
			}
			
			outputStream.flush();
			outputStream.close();
			inputStream.close();
			} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	private SQLiteDatabase openDatabase(){
		String path = DATABASE_PATH + DATABASE_NAME;
		db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE);
		return db;
	}
	
	public void close(){
		if(db != null){
			db.close();
		}
	}


}///


What I have tried:

I didn't find anything online related with this error and i don't know if i missed something in my DB helper class i tried upgrading SQLite libraries but that doesn't solve the problem i appreciate any help 🙏🙏
Posted
Updated 12-Jul-23 5:57am
Comments
Andre Oosthuizen 19-Jun-23 5:44am    
Your error is related to permissions or access issues on the Android device. I don't think it is directly related to the code you provided. If you comment out your code and run the app, do you still get the error or is it running fine?

Did you add the necessary permissions in your AndroidManifest.xml file?
brahim farhat (AAD) 12-Jul-23 10:58am    
See my solution

1 solution

Just changed checking method to this and the problem solved:
private boolean checkDataBase() {
		File databasePath = context.getDatabasePath(DATABASE_NAME);
		return databasePath.exists();
	}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900