MuscleTalk Bodybuilding Forum
Forums  Register  Login  My Profile  My Subscription  My Forums  Member List  Search  FAQ  Ticket List  Help MT  Log Out
Sponsor Message

www.thedoctorltd.co.uk
MuscleTalk Publications
Take Control Of YOUR Diet With...

Informed Bodybuilding Nutrition
Bodybuilding supplements at MuscleTalk Shop
Any Java programmers?
View related threads: (in this forum | in all forums)
Logged in as: Guest (JOIN FREE)
Users viewing this topic: none
  Printable Version
All Forums >> [General] >> General >> Any Java programmers? Page: [1] 2   next >   >>
Powered by: SuperiorSupplements.co.uk - Fast Free Delivery & GUARANTEED Lowest Prices on Reflex Nutrition, Optimum Nutrition, MuscleTech and Maximuscle - Train Hard - Recover Fast - Pay Less - BUY NOW!
Bookmark this thread:
Login
Message << Older Topic   Newer Topic >>
Any Java programmers? - Apr. 13 2008 22:44:04   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
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
Post #: 1
RE: Any Java programmers? - Apr. 13 2008 22:57:38   
sub_z3ro


Posts: 2323
Joined: Mar. 1 2005
From: Norf London/UEA
Status: offline
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

(in reply to ZEn101)
Post #: 2
RE: Any Java programmers? - Apr. 13 2008 22:59:24   
cliff_vtr


Posts: 11279
Joined: Apr. 29 2004
From: Nr Bournemouth
Status: offline
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.3K BW
160K Squat
102.5K Bench
210K Deadlift (Watch this space...220K will be falling soon)

My Journal

(in reply to ZEn101)
Post #: 3
RE: Any Java programmers? - Apr. 13 2008 23:01:16   
sub_z3ro


Posts: 2323
Joined: Mar. 1 2005
From: Norf London/UEA
Status: offline
^^^^ what he said actually!

_____________________________

AKE FOR MOD

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

(in reply to cliff_vtr)
Post #: 4
RE: Any Java programmers? - Apr. 13 2008 23:03:34   
cliff_vtr


Posts: 11279
Joined: Apr. 29 2004
From: Nr Bournemouth
Status: offline
btw there is a lot of nesting of "if" and "for" loops. I would factor it to make it more readable

_____________________________

73.3K BW
160K Squat
102.5K Bench
210K Deadlift (Watch this space...220K will be falling soon)

My Journal

(in reply to sub_z3ro)
Post #: 5
RE: Any Java programmers? - Apr. 13 2008 23:19:44   
Paracelsus


Posts: 2981
Joined: Jun. 17 2006
Status: online
What is blockCount?

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


(in reply to cliff_vtr)
Post #: 6
RE: Any Java programmers? - Apr. 13 2008 23:29:09   
Dan Nukem


Posts: 9392
Joined: Sep. 21 2002
From: Ireland
Status: offline
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.

(in reply to Paracelsus)
Post #: 7
RE: Any Java programmers? - Apr. 14 2008 0:16:59   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
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

(in reply to Dan Nukem)
Post #: 8
RE: Any Java programmers? - Apr. 14 2008 0:19:02   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
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

(in reply to ZEn101)
Post #: 9
RE: Any Java programmers? - Apr. 14 2008 0:21:13   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
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

(in reply to ZEn101)
Post #: 10
RE: Any Java programmers? - Apr. 14 2008 1:34:45   
Paracelsus


Posts: 2981
Joined: Jun. 17 2006
Status: online
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 -- Apr. 14 2008 1:35:48 >

(in reply to ZEn101)
Post #: 11
RE: Any Java programmers? - Apr. 14 2008 9:02:33   
Dan Nukem


Posts: 9392
Joined: Sep. 21 2002
From: Ireland
Status: offline

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!

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?

(in reply to ZEn101)
Post #: 12
RE: Any Java programmers? - Apr. 14 2008 9:03:43   
Dan Nukem


Posts: 9392
Joined: Sep. 21 2002
From: Ireland
Status: offline

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)


(in reply to ZEn101)
Post #: 13
RE: Any Java programmers? - Apr. 14 2008 9:06:52   
Dan Nukem


Posts: 9392
Joined: Sep. 21 2002
From: Ireland
Status: offline
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

(in reply to Dan Nukem)
Post #: 14
RE: Any Java programmers? - Apr. 14 2008 10:33:26   
cliff_vtr


Posts: 11279
Joined: Apr. 29 2004
From: Nr Bournemouth
Status: offline
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.3K BW
160K Squat
102.5K Bench
210K Deadlift (Watch this space...220K will be falling soon)

My Journal

(in reply to Dan Nukem)
Post #: 15
RE: Any Java programmers? - Apr. 14 2008 12:52:15   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
ARRAYSIZE is a gloabal constan t to that class, the array hsas 28 positionsin it



_____________________________

My journal

Email me food

(in reply to cliff_vtr)
Post #: 16
RE: Any Java programmers? - Apr. 14 2008 14:04:57   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
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

(in reply to ZEn101)
Post #: 17
RE: Any Java programmers? - Apr. 14 2008 15:31:14   
Dan Nukem


Posts: 9392
Joined: Sep. 21 2002
From: Ireland
Status: offline
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)


(in reply to ZEn101)
Post #: 18
RE: Any Java programmers? - Apr. 14 2008 17:20:48   
ZEn101


Posts: 604
Joined: Jun. 6 2006
Status: offline
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

(in reply to Dan Nukem)
Post #: 19
RE: Any Java programmers? - Apr. 14 2008 22:12:30   
Paracelsus


Posts: 2981
Joined: Jun. 17 2006
Status: online
Can't answer that without seeing the relevant code mate.

(in reply to ZEn101)
Post #: 20
Page:   [1] 2   next >   >>
All Forums >> [General] >> General >> Any Java programmers? Page: [1] 2   next >   >>
Jump to:

Google
 
Webwww.MuscleTalk.co.uk


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

Muscle Building Nutrition
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition