• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ArrayIndexOutOfBoundsException: 1

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




(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>
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never disappointed at this forum. Always got positive & accurate replies

The problem fixed. Thanks from the core of my heart. Appreciated

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic