Tuesday, May 14, 2013

[android help] 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 for game menu
*/
@Override
public void onClick(View v) {
Intent i;

switch (v.getId()){
case R.id.playBtn :
//once logged in, load the main page
//Log.d("LOGIN", "User has started the game");

//Get Question set //
List questions = getQuestionSetFromDb();

//Initialise Game with retrieved question set ///
GamePlay c = new GamePlay();
c.setQuestions(questions);
c.setNumRounds(getNumQuestions());
((ChuckApplication)getApplication()).setCurrentGame(c);

//Start Game Now.. //
i = new Intent(this, QuestionActivity.class);
startActivityForResult(i, Constants.PLAYBUTTON);
break;

case R.id.rulesBtn :
i = new Intent(this, RulesActivity.class);
startActivityForResult(i, Constants.RULESBUTTON);
break;

case R.id.settingsBtn :
i = new Intent(this, SettingsActivity.class);
startActivityForResult(i, Constants.SETTINGSBUTTON);
break;

case R.id.exitBtn :
finish();
break;
}

}


/**
* Method that retrieves a random set of questions from
* the database for the given difficulty
* @return
* @throws Error
*/
private List getQuestionSetFromDb() throws Error {
int diff = getDifficultySettings();
int numQuestions = getNumQuestions();
DBHelper myDbHelper = new DBHelper(this);
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
List questions = myDbHelper.getQuestionSet(diff, numQuestions);
myDbHelper.close();
return questions;
}


/**
* Method to return the difficulty settings
* @return
*/
private int getDifficultySettings() {
SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
int diff = settings.getInt(Constants.DIFFICULTY, Constants.MEDIUM);
return diff;
}

/**
* Method to return the number of questions for the game
* @return
*/
private int getNumQuestions() {
SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
int numRounds = settings.getInt(Constants.NUM_ROUNDS, 20);
return numRounds;
}


}


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


Logcat messaege:



`05-14 07:44:38.109: E/Trace(723): error opening trace file: No such file or directory (2)
05-14 07:44:39.629: D/dalvikvm(723): GC_FOR_ALLOC freed 203K, 13% free 2480K/2828K, paused 330ms, total 366ms
05-14 07:44:40.249: I/Choreographer(723): Skipped 69 frames! The application may be doing too much work on its main thread.
05-14 07:44:40.859: D/gralloc_goldfish(723): Emulator without GPU emulation detected.
05-14 07:44:57.139: E/SQLiteLog(723): (14) cannot open file at line 30176 of [00bb9c9ce4]
05-14 07:44:57.139: E/SQLiteLog(723): (14) os_unix.c:30176: (2) open(/data/data/com.pixy.quiz/databases/questionsDb) -
05-14 07:44:57.299: E/SQLiteDatabase(723): Failed to open database '/data/data/com.pixy.quiz/databases/questionsDb'.
05-14 07:44:57.299: E/SQLiteDatabase(723): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
05-14 07:44:57.299: E/SQLiteDatabase(723): at com.pixy.quiz.db.DBHelper.checkDataBase(DBHelper.java:69)
05-14 07:44:57.299: E/SQLiteDatabase(723): at com.pixy.quiz.db.DBHelper.createDataBase(DBHelper.java:46)
05-14 07:44:57.299: E/SQLiteDatabase(723): at com.pixy.quiz.SplashActivity.getQuestionSetFromDb(SplashActivity.java:97)
05-14 07:44:57.299: E/SQLiteDatabase(723): at com.pixy.quiz.SplashActivity.onClick(SplashActivity.java:55)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.view.View.performClick(View.java:4204)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.view.View$PerformClick.run(View.java:17355)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.os.Handler.handleCallback(Handler.java:725)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.os.Looper.loop(Looper.java:137)
05-14 07:44:57.299: E/SQLiteDatabase(723): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-14 07:44:57.299: E/SQLiteDatabase(723): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 07:44:57.299: E/SQLiteDatabase(723): at java.lang.reflect.Method.invoke(Method.java:511)
05-14 07:44:57.299: E/SQLiteDatabase(723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-14 07:44:57.299: E/SQLiteDatabase(723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-14 07:44:57.299: E/SQLiteDatabase(723): at dalvik.system.NativeStart.main(Native Method)
05-14 07:44:57.369: D/dalvikvm(723): GC_CONCURRENT freed 276K, 14% free 2633K/3052K, paused 73ms+45ms, total 220ms
05-14 07:44:57.610: D/AndroidRuntime(723): Shutting down VM
05-14 07:44:57.610: W/dalvikvm(723): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-14 07:44:57.649: E/AndroidRuntime(723): FATAL EXCEPTION: main
05-14 07:44:57.649: E/AndroidRuntime(723): java.lang.ClassCastException: android.app.Application cannot be cast to com.pixy.quiz.ChuckApplication
05-14 07:44:57.649: E/AndroidRuntime(723): at com.pixy.quiz.SplashActivity.onClick(SplashActivity.java:61)
05-14 07:44:57.649: E/AndroidRuntime(723): at android.view.View.performClick(View.java:4204)
05-14 07:44:57.649: E/AndroidRuntime(723): at android.view.View$PerformClick.run(View.java:17355)
05-14 07:44:57.649: E/AndroidRuntime(723): at android.os.Handler.handleCallback(Handler.java:725)
05-14 07:44:57.649: E/AndroidRuntime(723): at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 07:44:57.649: E/AndroidRuntime(723): at android.os.Looper.loop(Looper.java:137)
05-14 07:44:57.649: E/AndroidRuntime(723): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-14 07:44:57.649: E/AndroidRuntime(723): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 07:44:57.649: E/AndroidRuntime(723): at java.lang.reflect.Method.invoke(Method.java:511)
05-14 07:44:57.649: E/AndroidRuntime(723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-14 07:44:57.649: E/AndroidRuntime(723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-14 07:44:57.649: E/AndroidRuntime(723): at dalvik.system.NativeStart.main(Native Method)
05-14 07:49:57.010: I/Process(723): Sending signal. PID: 723 SIG: 9
`


My BDHelper Class:


public class DBHelper extends SQLiteOpenHelper{



//The Android's default system path of your 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 and keeps a reference of the passed context in order to access to the application assets and resources.
* @param context
*/
public DBHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}

/**
* Creates a empty database on the system and rewrites it with your own database.
* */
public void createDataBase() throws IOException{

boolean dbExist = checkDataBase();
if(!dbExist)
{
//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");
}
}
}

/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
* @return true if it exists, false if it 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 your database from your local assets-folder to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDataBase() throws IOException{

//Open your local db as the input stream
InputStream myInput = myContext.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;
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 your public helper methods to access and get content from the database.
// You could return cursors by doing "return myDataBase.query(....)" so it'd be easy
// to you to create adapters for your views.




public List getQuestionSet(int difficulty, int numQ){
List questionSet = new ArrayList();
Cursor c = myDataBase.rawQuery("SELECT * FROM question WHERE DIFFICULTY=" + difficulty +
" ORDER BY 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;
}


}



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...