Any Java programmers? (Full Version)

All Forums >> [General] >> General >> Any Java programmers?




Message
(for even more bodybuilding questions answered, check out the main forum at: www.MuscleTalk.co.uk)



ZEn101 -> Any Java programmers? (Apr. 13 2008 22:44:04)

The following code is semi self explanatory. The problem is that the .length() method isn't working or appearing in the suggestion list when i press '.'

The highlighted bit is the problem: i want; i < main.blockCount[].length();


private void processBlockCollision(Main main)
{
for (int i = 0; i < main.blockCount; i++)
{
if (checkCollision(main.blocks))
{
String score;
int scorei;
for(int l = 0; l < dontCount[ARRAYSIZE]; l++)
{
if (i != dontCount[j])
{
score = main.score.getText();
scorei = Integer.valueOf(score);scorei = scorei + 10;
//Testing
//System.out.println(scorei);
score = String.valueOf(scorei);main.score.setText(score);
main.blocks.setVisible(false);
// Add collision identity to dontCount list.
dontCount[j] = i;
j++;
}
}
}
}
}


HELPHELP!



sub_z3ro -> RE: Any Java programmers? (Apr. 13 2008 22:57:38)

is blockcount an integer and have you included any libraries you may need?

sub



cliff_vtr -> RE: Any Java programmers? (Apr. 13 2008 22:59:24)

I havent done Java but am a C/C++/C# programmer. C# is very similar to Java.

mainblock its an array, so there probably isnt a Length() method. What do you want the total number of elements in the array ??. If so there probably is something else you can use, what about sizeof ??

Sizeof returns the total length in bytes usually, so then divide that by the unit size. for example

int test [10];
int numberOfElements = sizeof(test)/sizeof(int);



sub_z3ro -> RE: Any Java programmers? (Apr. 13 2008 23:01:16)

^^^^ what he said actually!



cliff_vtr -> RE: Any Java programmers? (Apr. 13 2008 23:03:34)

btw there is a lot of nesting of "if" and "for" loops. I would factor it to make it more readable



Paracelsus -> RE: Any Java programmers? (Apr. 13 2008 23:19:44)

What is blockCount?

If it's an array, .length should work. .length not .length(), it's a variable.




Dan Nukem -> RE: Any Java programmers? (Apr. 13 2008 23:29:09)

Where did you initialise blockCount?

What type of variable is it?

Can you post the system output - maybe able to determine the problem from the log

if its an array, you still need to initialise it.



ZEn101 -> RE: Any Java programmers? (Apr. 14 2008 0:16:59)

SORRY - highlighted wrong bit >> new highlighted bit is an integer array. It is initilaised, i am aware of both methods usable they always work apart from this instance ie .size() .length() .sizeOf() etc... none seem to be applicable this array is declared in the class aswell oh and yes the util import is there ...any other ideas thansk for inputs so far, nice to know there are some programmers here![:D]

Ps.You'll have to excuse the lack of indentation its all god in my program but changes when i paste in this window!! no allowance for tabs


private void processBlockCollision(Main main)
{
for (int i = 0; i < main.blockCount; i++)
{
if (checkCollision(main.blocks))
{
String score;
int scorei;
for(int l = 0; l < dontCount[ARRAYSIZE]; l++)
{
if (i != dontCount[j])
{
score = main.score.getText();
scorei = Integer.valueOf(score);scorei = scorei + 10;
//Testing
//System.out.println(scorei);
score = String.valueOf(scorei);main.score.setText(score);
main.blocks.setVisible(false);
// Add collision identity to dontCount list.
dontCount[j] = i;
j++;
}
}
}
}
}


HELPHELP!



ZEn101 -> RE: Any Java programmers? (Apr. 14 2008 0:19:02)

Instead of methods u can see i tried adding the constant of array size: this is my error, but fixing this isnt really the solution

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 28



ZEn101 -> RE: Any Java programmers? (Apr. 14 2008 0:21:13)

for(int l = 0; l < dontCount[].length; l++) i otiginally did this but its not the variable i want it comes up with C:\Users\James Rose\Documents\NetBeansProjects\Pong\src\Ball.java:106: class expected



Paracelsus -> RE: Any Java programmers? (Apr. 14 2008 1:34:45)

Take off the [] and it should work

if dontCount is an array, 'dontCount.length' is an int representing the size of the array



Dan Nukem -> RE: Any Java programmers? (Apr. 14 2008 9:02:33)


quote:

ORIGINAL: ZEn101

SORRY - highlighted wrong bit >> new highlighted bit is an integer array. It is initilaised, i am aware of both methods usable they always work apart from this instance ie .size() .length() .sizeOf() etc... none seem to be applicable this array is declared in the class aswell oh and yes the util import is there ...any other ideas thansk for inputs so far, nice to know there are some programmers here![:D]

Ps.You'll have to excuse the lack of indentation its all god in my program but changes when i paste in this window!! no allowance for tabs


private void processBlockCollision(Main main)
{
for (int i = 0; i < main.blockCount; i++)
{
if (checkCollision(main.blocks))
{
String score;
int scorei;
for(int l = 0; l < dontCount[ARRAYSIZE]; l++)
{
if (i != dontCount[j])
{
score = main.score.getText();
scorei = Integer.valueOf(score);scorei = scorei + 10;
//Testing
//System.out.println(scorei);
score = String.valueOf(scorei);main.score.setText(score);
main.blocks.setVisible(false);
// Add collision identity to dontCount list.
dontCount[j] = i;
j++;
}
}
}
}
}


HELPHELP!



Oh god, its been too long, but anyway.

Where did you initialise 'arraySize'?
Is it a global variable?



Dan Nukem -> RE: Any Java programmers? (Apr. 14 2008 9:03:43)


quote:

ORIGINAL: ZEn101

Instead of methods u can see i tried adding the constant of array size: this is my error, but fixing this isnt really the solution

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 28


ArrayIndexOutOfBoundsException

-
this basically means that the array is size 0, and your trying to put something into position x+1 (which doesn't exist)




Dan Nukem -> RE: Any Java programmers? (Apr. 14 2008 9:06:52)

Have a quick browse off this, gives the utter basics:

http://learning.north.londonmet.ac.uk/java1/lm_jav1_arrays/lm_jav1_arrays_t.htm



cliff_vtr -> RE: Any Java programmers? (Apr. 14 2008 10:33:26)

everytime you add a new item to the array, you have to first resize it and make it 1 bigger.

Personally I'd use a List, its easier to use and manage.

I wasnt refering to the tabs, I was refering to the program structure, its not good pratice to have lots of nesting. So take out the inner "For" loop and make it a method in itself which then gets called from the orignal method. It will make it neater and easier to debug.



ZEn101 -> RE: Any Java programmers? (Apr. 14 2008 12:52:15)

ARRAYSIZE is a gloabal constan t to that class, the array hsas 28 positionsin it




ZEn101 -> RE: Any Java programmers? (Apr. 14 2008 14:04:57)

Thanks but i am more than familiar with th basics, this is an peculiar problem which hasn't arisen ever before. My guess is that the class imports have confused themselves.[8|]



Dan Nukem -> RE: Any Java programmers? (Apr. 14 2008 15:31:14)

ok, where is the global variable declared?

Try temporarily substituting a number for that global variable e.g 1000, just make the array bigger than it needs to be.

Failing that, go over to the Sun Forums, its been too long for me (nor do I miss it)




ZEn101 -> RE: Any Java programmers? (Apr. 14 2008 17:20:48)

I've solved it by doing it all in a different way, thanks alot for all of your inputs!!!![:)]

New question is when i reset a new instance of Ball ball = new Ball(355, 635); - why doesn't the ball repaint at new posx/posy from constructor?!

If i can get that done ill publish a version, if any body is interested![;)]



Paracelsus -> RE: Any Java programmers? (Apr. 14 2008 22:12:30)

Can't answer that without seeing the relevant code mate.



Page: [1] 2   next >   >>

© Muscle Talk Bodybuilding Forum

Check out the main forum at: www.MuscleTalk.co.uk


Forum Software © ASPPlayground.NET Advanced Edition