i have problem with ma app when i run it in genymotion it works fine but when i run it in the eclipse emulator or when i install it in my phone it crashes exactly when i try to open the sqlite database .....

the helper class

 public class Getdata extends SQLiteOpenHelper {


    @SuppressLint("SdCardPath") public static String db_path="data/data/za.example.drawer/databases";
    public static String db_name="student";

    public SQLiteDatabase myDB;
    public final Context cxt;
    public Getdata ourhelper;



    public Getdata (Context cxt) {
        super(cxt, db_name, null, 1);
        // TODO Auto-generated constructor stub
        this.cxt=cxt;
    }


     public void createDataBase() throws IOException{

         boolean dbExist = checkDataBase();

         if(dbExist){
         //do nothing - database already exist
         }else{

         //By calling this method and empty database will be created into the default system path
         //of your application so we are gonna be able to overwrite that database with our database.
         this.getReadableDatabase();

         try {

         copyDataBase();

         } catch (IOException e) {

         throw new Error("Error copying database");

         }
         }

         }
     private boolean checkDataBase(){

         SQLiteDatabase checkDB = null;

         try{
         String myPath = db_path + db_name;
         checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

         }catch(SQLiteException e){

         //database does't exist yet.

         }

         if(checkDB != null){

         checkDB.close();

         }

         return checkDB != null ? true : false;
         }


     private void copyDataBase() throws IOException{

        //Open your local db as the input stream
        InputStream myInput = cxt.getAssets().open(db_name);

        // Path to the just created empty db
        String outFileName = db_path + db_name;

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
        myOutput.write(buffer, 0, length);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();

        }

     public void openDataBase() throws SQLException{

        //Open the database
        String myPath = db_path + db_name;
        myDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }

        @Override
        public synchronized void close() {

        if(myDB != null)
            myDB.close();

        super.close();

        }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }
public String getdata() {
        // TODO Auto-generated method stub

         Cursor c = myDB.rawQuery("SELECT * FROM subjects", null);  
        String result="";




        for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
        {
            result= result + c.getString(0)  + " " + c.getString(1) + " " + c.getString(2) +"\n";
        }

        return result;
    }



public Getdata open() throws SQLException {
    // TODO Auto-generated method stub

            ourhelper =new Getdata(cxt);
            myDB= ourhelper.getWritableDatabase();
            return this;
}


public Cursor getdata(Context cxt2) {
    // TODO Auto-generated method stub
     Cursor c = myDB.rawQuery("SELECT * FROM ids", null);  
        String result="";

        return c;
    }

public Cursor getgrades ()
{ String st_id = Loginactivity.student_id;
    String query="SELECT * FROM GRADES=' "+st_id;
     Cursor c = myDB.rawQuery(query, null) ;
        String result="";




        for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
        {
            result= result + c.getString(0)  + " " +  " " + c.getString(2) +"\n";
        }

        return c;
    }


 public String getvission ()
       {  Cursor c = myDB.rawQuery("SELECT * FROM vission", null);  
          String result="";




     for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
    {
    result= result + c.getString(1)  +"\n";
     }

            return result;
    }

 public String getgolse ()
 {  Cursor c = myDB.rawQuery("SELECT * FROM golse", null);  
    String result="";




for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
{
result= result + c.getString(0)  +  "\n";
}

      return result;
}
 public String getsystem ()
 {  Cursor c = myDB.rawQuery("SELECT * FROM system", null);  
    String result="";




for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
{
result= result + c.getString(0)  +  "\n";
}

      return result;
}
 public String getfets ()
 {  Cursor c = myDB.rawQuery("SELECT * FROM featurs", null);  
    String result="";




for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
{
result= result + c.getString(0)  +  "\n";
}

      return result;
}

 public String getregs ()
 {  Cursor c = myDB.rawQuery("SELECT * FROM Regs", null);  
    String result="";




for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
{
result= result + c.getString(0)  +  "\n";
}

      return result;
}

 public String getexeps ()
 {  Cursor c = myDB.rawQuery("SELECT * FROM Exeps", null);  
    String result="";




for (c.moveToFirst(); !c.isAfterLast();c.moveToNext())
{
result= result + c.getString(0)  +  "\n";
}

      return result;
}

class that query the database

    public class Unv_vission extends MainActivity  implements OnItemClickListener {

    TextView tx_ab ;
    Context cxt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vission_xml);
        TextView tv =(TextView) findViewById(R.id.tvission);
        Getdata  info = new Getdata (this);
        info.open();
        String data=info.getvission();
        info.close();
        tv.setText(data);

    }

& this is the logcat

    11-09 16:21:52.731: E/AndroidRuntime(744): FATAL EXCEPTION: main
11-09 16:21:52.731: E/AndroidRuntime(744): java.lang.RuntimeException: Unable to start activity ComponentInfo{za.example.drawer/za.example.drawer.Unv_syst}: android.database.sqlite.SQLiteException: no such table: system: , while compiling: SELECT * FROM system
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.os.Looper.loop(Looper.java:137)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.ActivityThread.main(ActivityThread.java:4340)
11-09 16:21:52.731: E/AndroidRuntime(744):  at java.lang.reflect.Method.invokeNative(Native Method)
11-09 16:21:52.731: E/AndroidRuntime(744):  at java.lang.reflect.Method.invoke(Method.java:511)
11-09 16:21:52.731: E/AndroidRuntime(744):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-09 16:21:52.731: E/AndroidRuntime(744):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-09 16:21:52.731: E/AndroidRuntime(744):  at dalvik.system.NativeStart.main(Native Method)
11-09 16:21:52.731: E/AndroidRuntime(744): Caused by: android.database.sqlite.SQLiteException: no such table: system: , while compiling: SELECT * FROM system
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1538)
11-09 16:21:52.731: E/AndroidRuntime(744):  at za.example.drawer.Getdata.getsystem(Getdata.java:225)
11-09 16:21:52.731: E/AndroidRuntime(744):  at za.example.drawer.Unv_syst.onCreate(Unv_syst.java:19)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.Activity.performCreate(Activity.java:4465)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-09 16:21:52.731: E/AndroidRuntime(744):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
11-09 16:21:52.731: E/AndroidRuntime(744):  ... 11 more
11-09 16:21:56.640: E/InputDispatcher(88): Received spurious receive callback for unknown input channel.  fd=179, events=0x8

so anyone can see whats the problem i saw in the logcat that there is no such a table but the table is found in the database

Related posts

Recent Viewed