I know people asked for this question already. I followed the same answers which accepted by the user Answer. It worked fine for other Android versions but except Android 9.
private static String DB_NAME = "QuotesData.db";
private static String DB_PATH = "/data/data/[PACKAGE NAME]/databases/";
private void copyDataBase() throws IOException {
InputStream myInput = context.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
I'm getting null exception like no such table found.
Logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.in22labs.neet, PID: 23832
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.in22labs.neet/com.in22labs.neet.Quiz.Exammode}: android.database.sqlite.SQLiteException: no such table: Technical (code 1 SQLITE_ERROR): , while compiling: SELECT Id FROM Technical WHERE TopicId ='Che1'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Can anyone help? It perfectly works with other Android versions (Even in Android 8.1).
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exammode);
init();
Intent receivedIntent = this.getIntent();
subject = receivedIntent.getStringExtra("subject");
topicid = receivedIntent.getStringExtra("TopicId");
Log.e("Test","Exam page Created");
ConnectionDetector cd=new ConnectionDetector(Exammode.this);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("NEET");
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.open, R.string.close);
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
dbt = new DataBaseTechnical(Exammode.this);
getQno=dbt.getQuesNo(topicid);
InsertQuestionRandom();
InsertQuestionRandom method
private void InsertQuestionRandom() {
System.out.println("Before shuffling, ArrayList contains : " +getQno);
Collections.shuffle(getQno);
System.out.println("After shuffling, ArrayList contains : " + getQno);
//Toast.makeText(myContext, (CharSequence) arrayList,Toast.LENGTH_SHORT).show();
for(int i=0; i<20 ;i++)
{
int Shuff=getQno.get(i);
dbt.SelectQuestSet(Shuff);
}
}