• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Calculating Score For Quiz App

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do make a quiz app for Android. I parse JSON datas and have them written to radio group with radiobuttons. I could not exactly calculate the score. I tried to write a isRightAnswer method but even so, when i call the method the app crashes. trueResult is my score variable. The matter is mostly about the last part of the don't waste time with parsing part upside.

I wonder if this expression is wrong?



Or this?



Here is my QuizActiviyAdjectives class.



If someone can write me the snippet or tips for the solution would be awesome. Thanks in advance.
 
ensar topbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is at this part.

if(((RadioButton) grp_options.getChildAt(grp_options.getCheckedRadioButtonId())).getText().equals(rightAnswers.get(i)))



Here is the log.

05-05 16:10:42.380: E/AndroidRuntime(16461): FATAL EXCEPTION: main
05-05 16:10:42.380: E/AndroidRuntime(16461): Process: org.example.ydsquizapp, PID: 16461
05-05 16:10:42.380: E/AndroidRuntime(16461): java.lang.NullPointerException
05-05 16:10:42.380: E/AndroidRuntime(16461): at org.example.ydsquizapp.QuizActivityAdjectives$1.onClick(QuizActivityAdjectives.java:124)
05-05 16:10:42.380: E/AndroidRuntime(16461): at android.view.View.performClick(View.java:4461)
05-05 16:10:42.380: E/AndroidRuntime(16461): at android.view.View$PerformClick.run(View.java:18523)
05-05 16:10:42.380: E/AndroidRuntime(16461): at android.os.Handler.handleCallback(Handler.java:733)
05-05 16:10:42.380: E/AndroidRuntime(16461): at android.os.Handler.dispatchMessage(Handler.java:95)
05-05 16:10:42.380: E/AndroidRuntime(16461): at android.os.Looper.loop(Looper.java:136)
05-05 16:10:42.380: E/AndroidRuntime(16461): at android.app.ActivityThread.main(ActivityThread.java:5118)
05-05 16:10:42.380: E/AndroidRuntime(16461): at java.lang.reflect.Method.invokeNative(Native Method)
05-05 16:10:42.380: E/AndroidRuntime(16461): at java.lang.reflect.Method.invoke(Method.java:515)
05-05 16:10:42.380: E/AndroidRuntime(16461): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
05-05 16:10:42.380: E/AndroidRuntime(16461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
05-05 16:10:42.380: E/AndroidRuntime(16461): at dalvik.system.NativeStart.main(Native Method)



How can i fix it ? Another way to write it?
 
ensar topbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more edit...

The problem at this part of the block below.



Is there another way to write it? Sorry for flooding.
 
Shiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic