Getting Started - A Complete Android App walkthrough for Beginners (Part 2)
This is part 2 of a walkthrough of one of my first ever Android app, that happened to get a little bit of love in the android market, and for which the ENTIRE(!!) source code of the application is available to you good people to do whatever you want with.. see part 1 for more details of the app, what happened and the first steps in getting started!So far, we have created a simple Activity class, designed a layout with several buttons and then implemented an onClickListener within our Activity class to handle the required actions for all of our buttons. The remaining Activities are all fairly straight forward, and work in a similar fashion: the RulesActivity is just a simple activity what has a block of text with a brief description of the game; the SettingsActivity is a simple activity that has three radio buttons which allows the user to select the difficulty; the QuestionsActivity just displays a question and then a selection of multiple choice answers.
If you are not familiar with Activities then you can open up those other classes and see exactly what is going on, they are all pretty similar but each have slight nuances or differences in their components and actions.
At the moment the application is pretty simple – there is a basic welcome screen with some buttons, and once you start the game you get taken through the QuestionsActivity several times, refreshing with different questions until you have answered all the questions, and then at the end it displays a simple graphic based on your accumulated score. Easy right?!
Really, the only big gap in what is going on is the DB – all the questions need to be stored in the DB on the client device, and then that data needs to be accessed, so we basically need a DAO type class.
In this app, we have a single DBHelper class – you may want to wrap this with a service class, to allow better separation of layers and decreased coupling etc, but for the sake of this app, lets just jump into the DBHelper. To access the DB on Android you need to have your class extend SQLLiteOpenHelper, now lets walk through the code required
private static String DB_PATH = "/data/data/com.tmm.android.chuck/databases/"; private static String DB_NAME = "questionsDb"; private SQLiteDatabase myDataBase; private final Context myContext;
First of all we define some simple class member variables. The DB_PATH will be used later to access our file that contains all our questions in it, the DB_NAME is just a name of choice to reference the DB.
public DBHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; }
You have to make sure you override the constructor, as this needs to initialise the context and DB before starting.
Next we have the createDatabase method – this one is quite straight forward:
public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(!dbExist) { this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } }
As you can see, it simply checks if the DB already exists, if it doesn’t (in which case its the first time that the app has been launched on this device) then it calls the copyDataBase() method:
private void copyDataBase() throws IOException{ InputStream myInput = myContext.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); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); }
Again, this is pretty straight forward – it just opens an Input stream to read the file (our questions file that we have saved in the /assets/ directory) and then writes it to the output stream which has been set up to be our DB Path/Name. Easy right?
So now we pretty much have our DBHelper class that checks for an existing DB, if its found then it opens a connection, if its not then it loads the data (our question set) in for the first time.
Now, the only remaining thing that our helper needs to do is to be able to access the data so we can select questions to show the user. So let’s look at how we add some DAO access methods. What I have done here is create a simple method to return a (random) question set:
public ListgetQuestionSet(int difficulty, int numQ){ List questionSet = new ArrayList (); Cursor c = myDataBase.rawQuery("SELECT * FROM QUESTIONS WHERE DIFFICULTY=" + difficulty + " ORDER BY RANDOM() LIMIT " + numQ, null); while (c.moveToNext()){ 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; }
Here, I am modelling the questions in a pre-created “Question” class – this just has the necessary member variables so I can handle the questions more easily than having to try and deal with DB cursors throughout the code. In the above method we just call a pure SQL statement, and then iterate through the cursor to populate my Question ArrayList.
And thats it! There are some other Activity classes and helper classes running doing small things throughout the app, but the core features are covered, so feel free to have a look around the code, edit it, change the design and just generally have fun.
Thanks a lot for the tutorial and the source code!
ReplyDeleteIt really helps a beginner like me
Thank you! I got a few errors item, 6 actually in each file, with the following message : "the method onClick(View) of type AnswersActivity must override a superclass method" at line 61. The other files are EndgameActivity line 83, QuestionActivity line78, RulesActivity line 29, SettingsActivity line 69, SplashActivity line 45.
ReplyDeleteI reinstalled sun jdk to the latest package and can't get pass these errors. I am sure it's my end since your app works on the market. Can you help me out?
Thanks
theoliviaong@gmail.com
Olivia: I've had that error on a app i was creating and the problem was that i forgot to put the extends ... on the class definition
ReplyDeleteNuno -
ReplyDeleteThanks for your quick reply. I got passed the errors without extending anything. But when I ran the apps, it forces close when "play" is pressed. I am a beginner so I am still trying to figure it out.
Wow thank you, I have been searching and searching this should point me in the right direction.
ReplyDelete@Olivia - what did you do to get past the first errors you were getting? If you post the log of the errors you are getting now I might be able to help.
ReplyDelete@psy-chotic - glad it could help!
robbo- I reinstalled jdk twice before the errors went away but now I get force close errors almost everytime I hit the Play button. Here is the log:
ReplyDelete07-24 17:16:08.855: INFO/ActivityManager(52): Start proc com.tmm.android.chuck for activity com.tmm.android.chuck/.SplashActivity: pid=392 uid=10028 gids={1015}
07-24 17:16:08.975: DEBUG/ddm-heap(392): Got feature list request
07-24 17:16:09.035: INFO/UsageStats(52): Unexpected resume of com.tmm.android.chuck while already resumed in com.tmm.android.chuck
07-24 17:16:09.045: INFO/ActivityManager(52): Displayed activity com.tmm.android.chuck/.SplashActivity: 202 ms (total 2214 ms)
07-24 17:16:09.155: DEBUG/dalvikvm(392): GC freed 690 objects / 54328 bytes in 34ms
07-24 17:16:09.195: WARN/InputManagerService(52): Got RemoteException sending setActive(false) notification to pid 382 uid 10028
07-24 17:16:14.406: DEBUG/dalvikvm(95): GC freed 98 objects / 4872 bytes in 113ms
07-24 17:17:20.226: INFO/ActivityManager(52): Starting activity: Intent { cmp=com.tmm.android.chuck/.QuestionActivity }
07-24 17:17:20.266: DEBUG/AndroidRuntime(392): Shutting down VM
07-24 17:17:20.266: WARN/dalvikvm(392): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): Uncaught handler: thread main exiting due to uncaught exception
ReplyDelete07-24 17:17:20.266: ERROR/AndroidRuntime(392): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tmm.android.chuck/com.tmm.android.chuck.QuestionActivity}: java.lang.IndexOutOfBoundsException: Invalid location 0, size is 0
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.os.Looper.loop(Looper.java:123)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at java.lang.reflect.Method.invoke(Method.java:521)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at dalvik.system.NativeStart.main(Native Method)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): Caused by: java.lang.IndexOutOfBoundsException: Invalid location 0, size is 0
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at java.util.ArrayList.get(ArrayList.java:341)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at com.tmm.android.chuck.quiz.GamePlay.getNextQuestion(GamePlay.java:112)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at com.tmm.android.chuck.QuestionActivity.onCreate(QuestionActivity.java:39)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): ... 11 more
07-24 17:17:20.276: INFO/Process(52): Sending signal. PID: 392 SIG: 3
07-24 17:17:20.276: INFO/dalvikvm(392): threadid=7: reacting to signal 3
07-24 17:17:20.276: ERROR/dalvikvm(392): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
07-24 17:17:30.277: WARN/ActivityManager(52): Activity idle timeout for HistoryRecord{44eb6c38 com.tmm.android.chuck/.QuestionActivity}
07-24 17:18:05.466: INFO/Process(392): Sending signal. PID: 392 SIG: 9
07-24 17:18:05.496: INFO/ActivityManager(52): Process com.tmm.android.chuck (pid 392) has died.
07-24 17:18:05.496: INFO/WindowManager(52): WIN DEATH: Window{44eaf110 com.tmm.android.chuck/com.tmm.android.chuck.SplashActivity paused=false}
07-24 17:18:05.506: INFO/ActivityManager(52): Start proc com.tmm.android.chuck for activity com.tmm.android.chuck/.SplashActivity: pid=446 uid=10028 gids={1015}
07-24 17:18:05.676: DEBUG/ddm-heap(446): Got feature list request
07-24 17:18:05.696: INFO/UsageStats(52): Unexpected resume of com.tmm.android.chuck while already resumed in com.tmm.android.chuck
07-24 17:18:05.846: DEBUG/dalvikvm(446): GC freed 717 objects / 55376 bytes in 44ms
07-24 17:18:05.896: WARN/InputManagerService(52): Got RemoteException sending setActive(false) notification to pid 392 uid 10028
07-24 17:18:05.976: INFO/ActivityManager(52): Displayed activity com.tmm.android.chuck/.SplashActivity: 477 ms (total 45739 ms)
I greatly appreciate you taking time and looking at this. ;)
ReplyDeleteOk, from looking at the log, you see:
ReplyDelete07-24 17:17:20.266: ERROR/AndroidRuntime(392): Caused by: java.lang.IndexOutOfBoundsException: Invalid location 0, size is 0
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at java.util.ArrayList.get(ArrayList.java:341)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at com.tmm.android.chuck.quiz.GamePlay.getNextQuestion(GamePlay.java:112)
07-24 17:17:20.266: ERROR/AndroidRuntime(392): at com.tmm.android.chuck.QuestionActivity.onCreate(QuestionActivity.java:39)
This is showing us that the onCreate() method in QuestionActivity attempts to call GamePlay.getNextQuestion() (line 39 - currentQ = currentGame.getNextQuestion();)
The error is due to no questions being available - the questions should be available in the DB as they are loaded first time the game is played.
I recommend trying:
1) Checking that in the assets folder there is the questionsDb file (this contains the questions)
2) When you start the app, look at the options settings - From memory I think the questions provided that get loaded in to the DB are only a selection of "Medium" difficulty - if you have set it to east/hard settings then it might fail to load a questions from the DB and therefore give you the indexOutOfBounds.
Let me know if either these fail and we can have a look at debugging further
robbo-
ReplyDeleteThank you for the assistance. I will try adding questions to either difficulty level and see if it fixes it. Have a great day!
Hi Robbo-
ReplyDeleteThe questionsDb file is present in asset folder. I modified difficulty settings in the DB using SQLite Manager to 1 for easy, left 2 for medium alone, and changed to 3 for difficult. Saved the file and ran it on the emulator. I encountered the crash again with the following log:
07-30 22:58:03.695: WARN/dalvikvm(565): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): FATAL EXCEPTION: main
07-30 22:58:03.695: ERROR/AndroidRuntime(565): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tmm.android.chuck/com.tmm.android.chuck.QuestionActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.os.Looper.loop(Looper.java:123)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at java.lang.reflect.Method.invoke(Method.java:521)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at dalvik.system.NativeStart.main(Native Method)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at java.util.ArrayList.get(ArrayList.java:311)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at com.tmm.android.chuck.quiz.GamePlay.getNextQuestion(GamePlay.java:112)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at com.tmm.android.chuck.QuestionActivity.onCreate(QuestionActivity.java:39)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-30 22:58:03.695: ERROR/AndroidRuntime(565): ... 11 more
07-30 22:58:03.705: WARN/ActivityManager(60): Force finishing activity com.tmm.android.chuck/.QuestionActivity
07-30 22:58:03.705: WARN/ActivityManager(60): Force finishing activity com.tmm.android.chuck/.SplashActivity
07-30 22:58:04.214: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{450a8c98 com.tmm.android.chuck/.QuestionActivity}
07-30 22:58:14.654: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{44f7bb30 com.tmm.android.chuck/.SplashActivity}
07-30 22:58:14.655: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{450a8c98 com.tmm.android.chuck/.QuestionActivity}
I am combing through the files but my programming knowledge is next to none so... :( I am trying to figure out what that "invalid index 0, size is 0" is all about.
ReplyDeleteThanks Robbo
@Olivia, the error you are experiencing is because the application is attempting to access the first element in an empty list:
ReplyDelete"invalid index 0" - The application assumes the list of questions will be correctly loaded from the DB, so attempts to access the first element (the first element in a list or array in java is index 0)
"size is 0" - as suggested, the size of the list is 0, so as the list is empty there is nothing in the list at index 0 so throws an error.
When you actually start the application in the emulator, if you click the "settings" button on the main menu, what difficulty setting is being defaulted? (there should be three check boxes)
Hi robbo
DeleteI am having the same issue as Olivia. I have tried all three difficulty levels, downloaded SQLite and added entries for all levels to the database and I still see the same errors. Any other things that I can try?
Regards,
Jay
I'm having a problem to where most of the questions that populate are nothing, just the '?' I've redone the table and made sure that there is a set number of questions and corresponding table id's to each yet, I'm lucky if it pulls even one of those questions during the quiz.
ReplyDeleteHi. Many thanks for this, but I am wondering how I can add my own questions and answers. I have opened the questionsDb file in eclipse and the questions are surrounded by lots of symbols that are difficaul to read. Do I need to install a Db reader to be able to add new/replace questions?
ReplyDeleteSorry...also would you be able to point me in the right direction if I wanted to use pictures for questions. i.e. if I wanted to say...Which country does this flag belong to? (display a picture of a flag)
ReplyDeleteHave you managed to work out how you add pictures to the questions? Im trying to do the same thing aswell
DeleteNot yet. It's something to do with changing the database questions from strings to blob type. thats as far as I have got with no success.
Deletehave u figured this out already?
DeleteWhere can I edit the questions in the database? Any help would be highly appreciated.
ReplyDeleteDownload SQLLite and then you can open/edit the QuestionsDB in the Assets folder.
DeleteThanks Leroy, I have sqlite database browser now. Besides SQLLite will that work too?
ReplyDeleteOpen SQLLITE then goto >> File>> Open database >> then brows to the QusetionsDB in the folder called assets within your project folder you can then edit the questions.
Deletei already edited the question in the database inside the assets folder but why when i run the apps the questions didn't change..??
Deletewhether there is to know how to add images in question? if it is there that can help in sharing? I really need it ..
ReplyDeletethank you
Did anyone ever solve Olivia's issue with the null database. I am having the exact same issue and have tried modifying the db with no success....
ReplyDeleteJay
The master please help me, how to insert image into a question? is there any tutorial or sample coding?
ReplyDeleteanyone help me.
thank you ..
Hi,
ReplyDeleteI am trying to create a new database for a different app with different tables and structure but have been unsuccessful thus far so I have come up with a few things I'm not sure about. Thanks in advance for advice and help.
I tried to create a new database with the same table structure as the one in the assets folder and populate it with some data. As far as I can see in the sqlite data browser I created it in from http://sqlitebrowser.sourceforge.net/ they appear identical. First strange thing, the new database file is only 4kb where if I deleted all the records and populated the database with new records containing the same data it is still 28kb.
I don't quite understand why when I open the questionsDb file in Eclipse that I see the old questions and answers surrounded by symbols.
The old database with the new content loads and displays the new content in the app just fine, but the new database with the same content, same tables and structure fails and the app force closes.
On a somewhat related note, I have been trying to create and fill the database by importing a CSV file into it to no success.
Thanks again for advice.
OK, I give Up!!! :-( :-(
ReplyDeleteThe question.xml file contains:
1) A LOGO at the top
2) A Group of 4 RADIO BUTTONS in the middle
3) A NEXT BUTTON at the bottom
HOW does the program line up the Questions and the Radio Buttons??
Is it MAGIC???
I think the Text is created in the file QuestionsActivity.Java
It makes a TextView named Option 1-4
But I don’t see HOW it is linked to the Radio Buttons so they align in the window
ALSO……
Does anyone know HOW to change the COLOR of the Radio Button when checked?
Thanks,
Kelly :-)
So Calico.. you deleted the existing database and created a new one? I've done given up last year. :) Do you mind exporting the new database that works for us to examine? and when you say the new database loads/display new content fine... are you saying the app work?!
ReplyDeleteThanks
Olivia, I had the same error as you from earlier. All I did was change the emulator to match the build target and it worked.
DeleteThank you so much for your tutorial, but how can i change difficulty settings on the questions?
ReplyDeleteIf i change half of the questions in SqlDB to 1 and i choose easy the app crashes?
Something i missed?
Found what it was, i had compiler 1.5 instead of 1.6 and I had deleted the @Overrides, changed to 1.6 and added the missing @overrides, now it works superb =) Thank you very very much!
DeleteHi Robbo,
ReplyDeleteI'm Nidhin (a beginner) plz help...
I've got an error just like Olivia, error on clicking "Play" button. plz check
// Compiled from InvocationTargetException.java (version 1.5 : 49.0, super bit)
public class java.lang.reflect.InvocationTargetException extends java.lang.Exception {
// Method descriptor #8 ()V
// Stack: 3, Locals: 1
protected InvocationTargetException();
0 aload_0 [this]
1 invokespecial java.lang.Exception() [1]
4 new java.lang.RuntimeException [2]
7 dup
8 ldc [3]
10 invokespecial java.lang.RuntimeException(java.lang.String) [4]
13 athrow
Line numbers:
[pc: 0, line: 5]
Local variable table:
[pc: 0, pc: 14] local: this index: 0 type: java.lang.reflect.InvocationTargetException
// Method descriptor #14 (Ljava/lang/Throwable;)V
// Stack: 3, Locals: 2
public InvocationTargetException(java.lang.Throwable exception);
0 aload_0 [this]
1 invokespecial java.lang.Exception() [1]
4 new java.lang.RuntimeException [2]
7 dup
8 ldc [3]
10 invokespecial java.lang.RuntimeException(java.lang.String) [4]
13 athrow
Line numbers:
[pc: 0, line: 6]
Local variable table:
[pc: 0, pc: 14] local: this index: 0 type: java.lang.reflect.InvocationTargetException
[pc: 0, pc: 14] local: exception index: 1 type: java.lang.Throwable
// Method descriptor #17 (Ljava/lang/Throwable;Ljava/lang/String;)V
// Stack: 3, Locals: 3
public InvocationTargetException(java.lang.Throwable exception, java.lang.String detailMessage);
0 aload_0 [this]
1 invokespecial java.lang.Exception() [1]
4 new java.lang.RuntimeException [2]
7 dup
8 ldc [3]
10 invokespecial java.lang.RuntimeException(java.lang.String) [4]
13 athrow
Line numbers:
[pc: 0, line: 7]
Local variable table:
[pc: 0, pc: 14] local: this index: 0 type: java.lang.reflect.InvocationTargetException
[pc: 0, pc: 14] local: exception index: 1 type: java.lang.Throwable
[pc: 0, pc: 14] local: detailMessage index: 2 type: java.lang.String
// Method descriptor #21 ()Ljava/lang/Throwable;
// Stack: 3, Locals: 1
public java.lang.Throwable getTargetException();
0 new java.lang.RuntimeException [2]
3 dup
4 ldc [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 8]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: java.lang.reflect.InvocationTargetException
// Method descriptor #21 ()Ljava/lang/Throwable;
// Stack: 3, Locals: 1
public java.lang.Throwable getCause();
0 new java.lang.RuntimeException [2]
3 dup
4 ldc [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 9]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: java.lang.reflect.InvocationTargetException
}
Hello Robbo,
ReplyDeleteMy log file is
08-01 15:22:23.022: E/AndroidRuntime(273): FATAL EXCEPTION: main
08-01 15:22:23.022: E/AndroidRuntime(273): java.lang.ClassCastException: android.app.Application
08-01 15:22:23.022: E/AndroidRuntime(273): at org.chuckapp.SplashActivity.onClick(SplashActivity.java:64)
08-01 15:22:23.022: E/AndroidRuntime(273): at android.view.View.performClick(View.java:2408)
08-01 15:22:23.022: E/AndroidRuntime(273): at android.view.View$PerformClick.run(View.java:8816)
08-01 15:22:23.022: E/AndroidRuntime(273): at android.os.Handler.handleCallback(Handler.java:587)
08-01 15:22:23.022: E/AndroidRuntime(273): at android.os.Handler.dispatchMessage(Handler.java:92)
08-01 15:22:23.022: E/AndroidRuntime(273): at android.os.Looper.loop(Looper.java:123)
08-01 15:22:23.022: E/AndroidRuntime(273): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 15:22:23.022: E/AndroidRuntime(273): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 15:22:23.022: E/AndroidRuntime(273): at java.lang.reflect.Method.invoke(Method.java:521)
08-01 15:22:23.022: E/AndroidRuntime(273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 15:22:23.022: E/AndroidRuntime(273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 15:22:23.022: E/AndroidRuntime(273): at dalvik.system.NativeStart.main(Native Method)
08-01 15:23:36.902: E/AndroidRuntime(320): FATAL EXCEPTION: main
08-01 15:23:36.902: E/AndroidRuntime(320): java.lang.ClassCastException: android.app.Application
08-01 15:23:36.902: E/AndroidRuntime(320): at org.chuckapp.SplashActivity.onClick(SplashActivity.java:64)
08-01 15:23:36.902: E/AndroidRuntime(320): at android.view.View.performClick(View.java:2408)
08-01 15:23:36.902: E/AndroidRuntime(320): at android.view.View$PerformClick.run(View.java:8816)
08-01 15:23:36.902: E/AndroidRuntime(320): at android.os.Handler.handleCallback(Handler.java:587)
08-01 15:23:36.902: E/AndroidRuntime(320): at android.os.Handler.dispatchMessage(Handler.java:92)
08-01 15:23:36.902: E/AndroidRuntime(320): at android.os.Looper.loop(Looper.java:123)
08-01 15:23:36.902: E/AndroidRuntime(320): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 15:23:36.902: E/AndroidRuntime(320): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 15:23:36.902: E/AndroidRuntime(320): at java.lang.reflect.Method.invoke(Method.java:521)
08-01 15:23:36.902: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 15:23:36.902: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 15:23:36.902: E/AndroidRuntime(320): at dalvik.system.NativeStart.main(Native Method)
Hi,
ReplyDeletehow can we replace your DB with a new one?
I created the new SQLite db, put it in the asset folder and modified accordingly the DBHelper.java class.
However, it still tries to load your (old) questions and the app crashes before loading my db... why?
Thanks a lot.
"Or change the javahelper to reload new database if it changed" . how can i do that sir ? im still new to this. and i need this for my upcoming final project . can you help ? or do you have a better source code than this ?
ReplyDeleteIf I load this app in the emulator it runs fine, if I try to put it on my phone from eclipse it crashes. Any Idea why?
ReplyDeletehow did you put the questions and the answers and how could i change them?
ReplyDelete