Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSF
Search Coderanch
Advance search
Google search
Register / Login
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:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
JSF
java.lang.IndexOutOfBoundsException
M Hasan
Ranch Hand
Posts: 35
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I copied line by line from a book there were several error fixed most of them. Now I am stuck.Please help:
public class QuizBean implements Serializable { private int currentProblem; private int tries; private int score; private String response = ""; private String correctAnswer; private ArrayList<com.corejsf.Problem> problems = new ArrayList<com.corejsf.Problem>(Arrays.asList( new com.corejsf.Problem( "What trademarked slogan describes Java development? Write once, ...", "run anywhere"), new com.corejsf.Problem( "What are the first 4 bytes of every class file (in hexadecimal)?", "CAFEBABE"), new com.corejsf.Problem( "What does this statement print? System.out.println(1+\"2\");", "12"), new com.corejsf.Problem( "Which Java keyword is used to define a subclass?", "extends"), new com.corejsf.Problem( "What was the original name of the Java programming language?", "Oak"), new com.corejsf.Problem( "Which java.util class describes a point in time?", "Date"))); public String getQuestion() { return problems.get(currentProblem).getQuestion(); } public String getAnswer() { return correctAnswer; } public int getScore() { return score; } public String getResponse() { return response; } public void setResponse(String newValue) { response = newValue; } //------------------------------------------------------------------------- public String AnswerAction() { tries++; if (problems.get(currentProblem).isCorrect(response)) { score++; nextProblem(); if (currentProblem == problems.size()) { return "done"; } else { return "success"; } } else if (tries == 1) { return "again"; } else { nextProblem(); if (currentProblem == problems.size()) { return "done"; } else { return "failure"; } } }//AnswerAction() public String startOverAction(){ Collections.shuffle(problems); currentProblem = 0; score = 0; tries = 0; response=""; return "startOver"; } //------------------------------------------------------------------------- private void nextProblem(){ correctAnswer = problems.get(currentProblem).getAnswer(); currentProblem++; tries = 0; response=""; } }
<?xml version="1.0"?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0"> <navigation-rule> <navigation-case> <from-outcome>startOver</from-outcome> <to-view-id>/index.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/again.xhtml</from-view-id> <navigation-case> <from-outcome>failure</from-outcome> <to-view-id>/failure.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <navigation-case> <from-outcome>failure</from-outcome> <to-view-id>/again.xhtml</to-view-id> </navigation-case> </navigation-rule> <application> <resource-bundle> <base-name>com.corejsf.messages</base-name> <var>msgs</var> </resource-bundle> </application> </faces-config>
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>#{msgs.title}</title> </h:head> <h:body> <h:form> <p>#{quizBean.question}</p> <p><h:inputText value="#{quizBean.response}"/></p> <p><h:commandButton value="#{msgs.checkAnswer}" actionListener="#{quizBean.AnswerAction}"/></p> </h:form> </h:body> </html>
I could trace the bug.Please help. The whole code is here:
github
Tim Holloway
Saloon Keeper
Posts: 25649
183
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Welcome to the JavaRanch!
Actually, if you could post the server log (stack trace) to this
thread
it would help a lot.
Sometimes the only way things ever got fixed is because people became uncomfortable.
M Hasan
Ranch Hand
Posts: 35
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at com.jsf.QuizBean.getQuestion(QuizBean.java:36) at com.jsf.QuizBean$$OwbNormalScopeProxy0.getQuestion(com/jsf/QuizBean.java) .....
M Hasan
Ranch Hand
Posts: 35
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I solved the issue .
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Update a Registration page using JSF and MySQL Database.
Providing anchor to columns in a datatable
Problem with attributes backing bean
Navigation rule not working
Target Unreachable, identifier 'employee' resolved to null
More...