| Author |
java.lang.ArrayIndexOutOfBoundsException: 1
|
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
(1) The parameter "answer[i]" have 3 parameters values
(2) The "correctAnswer[i]" also have 3 parameters values i.e. one parameter value as 1 and two are null. I tried to assign "0" to null values but my code is inserting into DB only "answer[i]" that has not null "correctAnswer[i]" i.e. one field out of three whereas I want to insert whole 3 fields as 'if they null then 0 and if not null then 1'
Thanks in advance>
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
Consider what the code looks like with indentation that matches it.
As you can see, this doesn't set the three values with anything. What if you ended the if statement earlier?
[edited to end code block properly]
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
Jeanne Boyarsky wrote:Consider what the code looks like with indentation that matches it.
As you can see, this doesn't set the three values with anything. What if you ended the if statement earlier?
[edited to end code block properly]
Thanks for your reply.
I edited as you directed but now not inserting any record. My new code
I think its not a if block problem but related to inserting two arrays at a time. I think when cursor is comming to answer[i] then i=0 but when its comming to correctAnswer[i] then it skipping correctAnswer[0] and working as correctAnswer[1]. This is the real problem. Is that what I think?
Thanks again and profound regards
|
 |
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
Can anybody please help me as this is 2nd day I stuck and not able to solve the problem.
Thanks again & best regards
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
Farakh khan wrote:I edited as you directed but now not inserting any record.
As it shouldn't - your code skips the whole block. That wasn't quite the edit I had in mind.
This assumes the arrays are the same length. If not, you have a more fundamental design problem that needs more custom logic.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
Farakh khan wrote:Can anybody please help me as this is 2nd day I stuck and not able to solve the problem.
Thanks again & best regards
Please keep in mind we are all volunteers and PatienceIsAVirtue
|
 |
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
I never disappointed at this forum. Always got positive & accurate replies
The problem fixed. Thanks from the core of my heart. Appreciated
|
 |
 |
|
|
subject: java.lang.ArrayIndexOutOfBoundsException: 1
|
|
|