• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Initialize  RSS feed

 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to add value in the double array which i cannot identify the size(length) of it,, which surely i got the error notify

the value that i will add it into the array occur from the calculation

i wanna get the result of calculation in the array in order to sort and extract only the 30 minimum value of it

and also need the index of each value

i would like to ask that how can i solve this problem in order to continue the less work



and this is my code

and here is my error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

anyones who know please help me, thanks so much for your time
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are these arrays declared and initialized: lengthCutInch and widthCutInch? It is possible that while accessing the element of lengthCutInch array an ArrayIndexOutOfBoundsException is thrown.

Please TellTheDetails and PostRealCode.
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is real code

 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stacktrace for the exception being thrown?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More directly, here, you create "kakWidth" as a zero-length array

double[] kakWidth = {};

And then here, you assume there are 20 elements in it, which there are not:



When you create kakWidth and kakLength, you need to make them 20 elements long, rather than 0:

double[] kakWidth = new double[20];
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't know about the exception at all

the error is on the kakWidth array

but i would like to know about the exception, too

thanks
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Ernest Friedman-Hill

the actual size of kakWidth is more than 100 possibles results

so i don't know how to do ...
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanaphorn Thongthien wrote:i don't know about the exception at all

the error is on the kakWidth array

but i would like to know about the exception, too

thanks


Ernest has pointed out the reason for the exception.

And when you would have executed this code- there would be a huge set of text posted on the command prompt- stating the Java class, methods, line numbers- That is called Stacktrace- basically shows the stack of methods called before the method which threw the exception was called. In the example you have given- it would be the main method throwing the exception.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanaphorn Thongthien wrote:to Ernest Friedman-Hill

the actual size of kakWidth is more than 100 possibles results

so i don't know how to do ...


How do you claim that it is more than 100 possible results? Are you retrieving the results from the dB? you should know the size of the array and use it while creating the array.
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i already do follow Ernest Friedman-Hill suggestion

and i would like to sort them by using


it's show

[6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5]

20 elements long and it not sort min > max

how can i solve it ?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanaphorn Thongthien wrote:i already do follow Ernest Friedman-Hill suggestion

and i would like to sort them by using


it's show

[6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5, 6.5]

20 elements long and it not sort min > max

how can i solve it ?


The printed array shows that all the elements in the array are similar- so how does the sort min > max come into picture here?

And have you solved your query which you had earlier posted?
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in you meaning i have to

divide my code into method

which have different duty

such as modularSize() ?

i will answer you actually i didn't do it yet ...

(i cann't do it T.T) i just greenhorn

how poor i am ...



 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually this is my one service in the my spring MVC project

the problem code that i have is the part that used to calculation

the require of the small service is only just return the collect value to other methods

the actual return result will be in list which i have to adapt again

the problem code here is the test for make new calculation and make the best result for my whole program

i have just no idea about the syntax array and initial so i post questions here T^T
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanaphorn Thongthien wrote: ... (i cann't do it T.T) ...

What doest T.T mean?

Thanaphorn Thongthien wrote: ... i have just no idea about the syntax array and initial so i post questions here T^T


You can read more about arrays here.
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T.T = crying face (my feeling)

cry because i cannot do it !
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanaphorn Thongthien wrote:T.T = crying face (my feeling)

cry because i cannot do it !


You can read more about arrays here.
 
Thanaphorn Thongthien
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i already read, but i still cannot solve my problem
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't write things like T.T because nobody knows what it means.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've read through this thread a couple of times now, and can't tell what the current problem is. Can you please post your current code, and state what the current problem is? If you get a compiler error, post that. If it runs but then throws an exception, post the exact and complete error message from when it bombs. If it runs, but just doesn't give the output you expect, post what the output is and what you expected it to be.
 
Jonathan De Vlas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change
to

you create an array with length 0. Pointing to a place of an array that doesnt exist is called a index out of bounds Exception (compilation error).

Easy example when you get this error:

 
Jonathan De Vlas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PS: if you run doesn't your command window say at which line of the code the compilation error started?

PPS: these are my first posts

cheers
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!