android - Logcat message: error opening trace file: No such file or directory (2) Can anyone help me? -


java code: public class splashactivity extends activity implements onclicklistener {

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.welcome);      //////////////////////////////////////////////////////////////////////     //////// game menu  /////////////////////////////////////////////////     button playbtn = (button) findviewbyid(r.id.playbtn);     playbtn.setonclicklistener(this);     button settingsbtn = (button) findviewbyid(r.id.settingsbtn);     settingsbtn.setonclicklistener(this);     button rulesbtn = (button) findviewbyid(r.id.rulesbtn);     rulesbtn.setonclicklistener(this);     button exitbtn = (button) findviewbyid(r.id.exitbtn);     exitbtn.setonclicklistener(this); }   /**  * listener game menu  */ @override public void onclick(view v) {     intent i;      switch (v.getid()){     case r.id.playbtn :         //once logged in, load main page         //log.d("login", "user has started game");          //get question set //         list<question> questions = getquestionsetfromdb();          //initialise game retrieved question set ///         gameplay c = new gameplay();         c.setquestions(questions);         c.setnumrounds(getnumquestions());         ((chuckapplication)getapplication()).setcurrentgame(c);            //start game now.. //         = new intent(this, questionactivity.class);         startactivityforresult(i, constants.playbutton);         break;      case r.id.rulesbtn :         = new intent(this, rulesactivity.class);         startactivityforresult(i, constants.rulesbutton);         break;      case r.id.settingsbtn :         = new intent(this, settingsactivity.class);         startactivityforresult(i, constants.settingsbutton);         break;      case r.id.exitbtn :         finish();         break;     }  }   /**  * method retrieves random set of questions  * database given difficulty  * @return  * @throws error  */ private list<question> getquestionsetfromdb() throws error {     int diff = getdifficultysettings();     int numquestions = getnumquestions();     dbhelper mydbhelper = new dbhelper(this);     try {         mydbhelper.createdatabase();     } catch (ioexception ioe) {         throw new error("unable create database");     }     try {         mydbhelper.opendatabase();     }catch(sqlexception sqle){         throw sqle;     }     list<question> questions = mydbhelper.getquestionset(diff, numquestions);     mydbhelper.close();     return questions; }   /**  * method return difficulty settings  * @return  */ private int getdifficultysettings() {     sharedpreferences settings = getsharedpreferences(constants.settings, 0);     int diff = settings.getint(constants.difficulty, constants.medium);     return diff; }  /**  * method return number of questions game  * @return  */ private int getnumquestions() {     sharedpreferences settings = getsharedpreferences(constants.settings, 0);     int numrounds = settings.getint(constants.num_rounds, 20);     return numrounds; } 

}

when hit play button, application stops. button has take new activity open quiz qith 4 option radio button connected sqlite database.

logcat messaege:

 `05-14 09:57:07.126: d/dalvikvm(19541): gc_concurrent freed 189k, 12% free 2676k/3016k, paused 19ms+7ms, total 108ms 05-14 09:57:07.126: d/dalvikvm(19541): wait_for_concurrent_gc blocked 47ms 05-14 09:57:07.486: i/choreographer(19541): skipped 55 frames!  application may doing work on main thread. 05-14 09:57:07.516: d/gralloc_goldfish(19541): emulator without gpu emulation detected. 05-14 09:57:10.116: d/androidruntime(19541): shutting down vm 05-14 09:57:10.116: w/dalvikvm(19541): threadid=1: thread exiting uncaught exception (group=0x40a71930) 05-14 09:57:10.146: e/androidruntime(19541): fatal exception: main 05-14 09:57:10.146: e/androidruntime(19541): java.lang.classcastexception: android.app.application cannot cast com.pixy.quiz.chuckapplication 05-14 09:57:10.146: e/androidruntime(19541):    @ com.pixy.quiz.splashactivity.onclick(splashactivity.java:61) 05-14 09:57:10.146: e/androidruntime(19541):    @ android.view.view.performclick(view.java:4204) 05-14 09:57:10.146: e/androidruntime(19541):    @ android.view.view$performclick.run(view.java:17355) 05-14 09:57:10.146: e/androidruntime(19541):    @ android.os.handler.handlecallback(handler.java:725) 05-14 09:57:10.146: e/androidruntime(19541):    @ android.os.handler.dispatchmessage(handler.java:92) 05-14 09:57:10.146: e/androidruntime(19541):    @ android.os.looper.loop(looper.java:137) 05-14 09:57:10.146: e/androidruntime(19541):    @ android.app.activitythread.main(activitythread.java:5041) 05-14 09:57:10.146: e/androidruntime(19541):    @ java.lang.reflect.method.invokenative(native method) 05-14 09:57:10.146: e/androidruntime(19541):    @ java.lang.reflect.method.invoke(method.java:511) 05-14 09:57:10.146: e/androidruntime(19541):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-14 09:57:10.146: e/androidruntime(19541):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-14 09:57:10.146: e/androidruntime(19541):    @ dalvik.system.nativestart.main(native method) 05-14 09:57:13.797: i/process(19541): sending signal. pid: 19541 sig: 9  ` 

my bdhelper class:

public class dbhelper extends sqliteopenhelper{

//the android's default system path of application database. private static string db_path = "/data/data/com.pixy.quiz/databases/"; private static string db_name = "questionsdb"; private sqlitedatabase mydatabase;  private final context mycontext;  /**  * constructor  * takes , keeps reference of passed context in order access application assets , resources.  * @param context  */ public dbhelper(context context) {     super(context, db_name, null, 1);     this.mycontext = context; }     /**  * creates empty database on system , rewrites own database.  * */ public void createdatabase() throws ioexception{      boolean dbexist = checkdatabase();     if(!dbexist)     {         //by calling method , empty database created default system path         //of application gonna able overwrite database our database.         this.getreadabledatabase();          try {             copydatabase();          } catch (ioexception e) {             throw new error("error copying database");         }     } }  /**  * check if database exist avoid re-copying file each time open application.  * @return true if exists, false if doesn't  */ 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; }  /**  * copies database local assets-folder created empty database in  * system folder, can accessed , handled.  * done transfering bytestream.  * */ private void copydatabase() throws ioexception{      //open local db input stream     inputstream myinput = mycontext.getassets().open(db_name);      // path created empty db     string outfilename = db_path + db_name;      //open empty db output stream     outputstream myoutput = new fileoutputstream(outfilename);      //transfer bytes inputfile outputfile     byte[] buffer = new byte[1024];     int length;     while ((length = myinput.read(buffer))>0){         myoutput.write(buffer, 0, length);     }      //close streams     myoutput.flush();     myoutput.close();     myinput.close();  }  public void opendatabase() throws sqlexception{     //open database     string mypath = db_path + db_name;     mydatabase = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly); }  @override public synchronized void close() {     if(mydatabase != null)         mydatabase.close();     super.close(); }  @override public void oncreate(sqlitedatabase db) { }  @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { }  // add public helper methods access , content database. // return cursors doing "return mydatabase.query(....)" it'd easy // create adapters views.     public list<question> getquestionset(int difficulty, int numq){     list<question> questionset = new arraylist<question>();     cursor c = mydatabase.rawquery("select * question difficulty=" + difficulty +             " order random() limit " + numq, null);     while (c.movetonext()){         //log.d("question", "question found in db: " + c.getstring(1));         question q = new question();         q.setquestion(c.getstring(1));         q.setanswer(c.getstring(2));         q.setoption1(c.getstring(3));         q.setoption2(c.getstring(4));         q.setoption3(c.getstring(5));         q.setrating(difficulty);         questionset.add(q);     }     return questionset; } 

}

manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pixy.quiz" android:versioncode="1" android:versionname="1.0" >  <uses-sdk     android:minsdkversion="8"     android:targetsdkversion="8" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.pixy.quiz.splashactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <activity android:name=".questionactivity" />     <activity android:name=".rulesactivity" />     <activity android:name=".endgameactivity" />     <activity android:name=".settingsactivity" />     <activity android:name=".answersactivity" /> </application> <application  android:allowbackup="true" android:name="com.pixy.quiz.chuckapplication"/> </manifest> 

when you're doing :

try {         mydbhelper.createdatabase();     } catch (ioexception ioe) {         throw new error("unable create database");     }     try {         mydbhelper.opendatabase();     }catch(sqlexception sqle){         throw sqle;     } 

you're trying open 2 times database. should have 1 instance of opened @ runtime.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -