Welcome to MuscleTalk !
Sponsor Message

www.thedoctorltd.co.uk
Prev Thread Prev Thread   Next Thread Next Thread
Sponsored by: Bodybuilding Warehouse - Amazing prices and FREE P&P on bodybuilding supplements from Gaspari, Anabolic Xtreme, Controlled Labs, ALRI & more!
 Any Java programmers?
Change Page: 12 > | Showing page 1 of 2, messages 1 to 20 of 24
Author Message
ZEn101

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
Any Java programmers? - 13 April 2008 22:44
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!
My journal

Email me food
Bodybuilding Warehouse Bodybuilding Warehouse - The best bodybuilding supplements from the best brands, Anabolic Xtreme, ALRI, Controlled Labs & more all with free delivery!
sub_z3ro

  • Total Posts : 2337
  • Reward points : 2791
  • Joined: 01/03/2005
  • Location: Norf London/UEA
  • Status: offline
RE: Any Java programmers? - 13 April 2008 22:57
is blockcount an integer and have you included any libraries you may need?

sub
AKE FOR MOD

List of people who aren't getting a sub_z3ro T-shirt:
1. James
cliff_vtr

  • Total Posts : 11478
  • Reward points : 3368
  • Joined: 29/04/2004
  • Location: Nr Bournemouth
  • Status: offline
RE: Any Java programmers? - 13 April 2008 22:59
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);
73.25K BW
160K Squat
102.5K Bench
220K Deadlift (3BW)

My Journal
sub_z3ro

  • Total Posts : 2337
  • Reward points : 2791
  • Joined: 01/03/2005
  • Location: Norf London/UEA
  • Status: offline
RE: Any Java programmers? - 13 April 2008 23:01
^^^^ what he said actually!
AKE FOR MOD

List of people who aren't getting a sub_z3ro T-shirt:
1. James
cliff_vtr

  • Total Posts : 11478
  • Reward points : 3368
  • Joined: 29/04/2004
  • Location: Nr Bournemouth
  • Status: offline
RE: Any Java programmers? - 13 April 2008 23:03
btw there is a lot of nesting of "if" and "for" loops. I would factor it to make it more readable
73.25K BW
160K Squat
102.5K Bench
220K Deadlift (3BW)

My Journal
Paracelsus

  • Total Posts : 3323
  • Reward points : 1874
  • Joined: 17/06/2006
  • Status: offline
RE: Any Java programmers? - 13 April 2008 23:19
What is blockCount?

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

Dan Nukem

  • Total Posts : 9806
  • Reward points : 4377
  • Joined: 21/09/2002
  • Location: Somewhere Offline
  • Status: offline
RE: Any Java programmers? - 13 April 2008 23:29
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

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 00:16
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!

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!
My journal

Email me food
ZEn101

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 00:19
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
My journal

Email me food
ZEn101

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 00:21
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
My journal

Email me food
Paracelsus

  • Total Posts : 3323
  • Reward points : 1874
  • Joined: 17/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 01:34
Take off the [] and it should work

if dontCount is an array, 'dontCount.length' is an int representing the size of the array
<message edited by Paracelsus on 14 April 2008 01:35>
Dan Nukem

  • Total Posts : 9806
  • Reward points : 4377
  • Joined: 21/09/2002
  • Location: Somewhere Offline
  • Status: offline
RE: Any Java programmers? - 14 April 2008 09:02


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!

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

  • Total Posts : 9806
  • Reward points : 4377
  • Joined: 21/09/2002
  • Location: Somewhere Offline
  • Status: offline
RE: Any Java programmers? - 14 April 2008 09:03


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

  • Total Posts : 9806
  • Reward points : 4377
  • Joined: 21/09/2002
  • Location: Somewhere Offline
  • Status: offline
RE: Any Java programmers? - 14 April 2008 09:06
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

  • Total Posts : 11478
  • Reward points : 3368
  • Joined: 29/04/2004
  • Location: Nr Bournemouth
  • Status: offline
RE: Any Java programmers? - 14 April 2008 10:33
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.
73.25K BW
160K Squat
102.5K Bench
220K Deadlift (3BW)

My Journal
ZEn101

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 12:52
ARRAYSIZE is a gloabal constan t to that class, the array hsas 28 positionsin it

My journal

Email me food
ZEn101

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 14:04
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.
My journal

Email me food
Dan Nukem

  • Total Posts : 9806
  • Reward points : 4377
  • Joined: 21/09/2002
  • Location: Somewhere Offline
  • Status: offline
RE: Any Java programmers? - 14 April 2008 15:31
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

  • Total Posts : 604
  • Reward points : 1606
  • Joined: 06/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 17:20
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!
My journal

Email me food
Paracelsus

  • Total Posts : 3323
  • Reward points : 1874
  • Joined: 17/06/2006
  • Status: offline
RE: Any Java programmers? - 14 April 2008 22:12
Can't answer that without seeing the relevant code mate.
Change Page: 12 > | Showing page 1 of 2, messages 1 to 20 of 24
Jump to:
Current active users
There are 0 members and 1 guests.
Icon Legend and Permission
  • New Messages
  • No New Messages
  • Hot Topic w/ New Messages
  • Hot Topic w/o New Messages
  • Locked w/ New Messages
  • Locked w/o New Messages
  • Read Message
  • Post New Thread
  • Reply to message
  • Post New Poll
  • Submit Vote
  • Post reward post
  • Delete my own posts
  • Delete my own threads
  • Rate post