GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Dec-2007, 13:00
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Extending the array elements


Hi,

JAVA Code:
double[] x=new double[num];
double[] xx=new double[num];
Java limits me to only 100 elements within the array. How can I declare that it extends this limit?

"Exception in thread "Thread-3" java.lang.ArrayIndexOutOfBoundsException: 100"

Thanks in advance.
Last edited by LuciWiz : 27-Dec-2007 at 15:39. Reason: Please insert your Java code between [java] & [/java] tags
  #2  
Old 25-Dec-2007, 15:26
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 959
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Extending the array elements


That doesn't sound like a limit on the array... that's sounds more like 'num' was initially 100 when created [0-99], and then a value was attempted to be set at index 100 [in thread 3 somewhere?], then exception.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 26-Dec-2007, 08:21
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Re: Extending the array elements


Opps....

My num and numBig were initialized to 500 and 100. However, when num becomes 110 it all stopped.

JAVA Code:
	private int num=500; // Number of red balls.
	private int numBig=100; // Number of red balls.
	boolean frozen=false; // Whether the simulation is stopped.
	private Graphics offscreen; // Offscreen buffer for double-buffering.
	Image offImage;
	Scope myScope; // Reference to the microscope view of this ball.
	Dimension thisSize; // Size of canvas.
	Thread animatorThread; // The thread of multi-threaded.
	// Because the balls live on a torus (wrap-around boundary conditions),
	// they can strike the blue particle on any side of the playing field.
	// offsets[][] carries the nine current locations of the blue ball.
	int[][] offsets;
	// Positions (x,y) and velocities (xx,yy) of all red balls.
	// Positions (bigx,bigy) and velocities (bigxvel,bigyvel) of all blue balls.
	double[] x=new double[num];
	double[] xx=new double[num];
	double[] y=new double[num];
	double[] yy=new double[num];

	double[] bigxvel=new double[numBig];
	double[] bigyvel=new double[numBig];
	double[] bigx=new double[numBig];
	double[] bigy=new double[numBig];

JAVA Code:
	public void init()
	{
	String sParam;
		int nBalls, nBigBalls;
		double dMassRatio, dAverageVelocity;
		ResourceBundle rb;

		// The resource bundle contains strings in various languages.
		// See the CollisionStrings*.properties files.
		String sUseRB = this.getParameter("international");
		rb = null;
		if ((sUseRB == null) || !sUseRB.equalsIgnoreCase("no")) {
			String sLang = this.getParameter("language");
			String sCountry = this.getParameter("country");
			try {
				if (sLang == null)
					rb = ResourceBundle.getBundle(sResource, Locale.getDefault());
				else {
					Locale thisloc;
					if (sCountry == null)
						thisloc = new Locale(sLang,"");
					else
						thisloc = new Locale(sLang,sCountry);
					rb = ResourceBundle.getBundle(sResource,thisloc);
				}
			} catch (java.lang.ClassFormatError e) {
				System.out.println("ClassFormatError: "+e.getMessage());
				rb = null;
			} catch (MissingResourceException e) {
				System.out.println("Missing Resource: "+e.getMessage());
				rb = null;
			}
		}
		if (rb!=null) {
			try {
				sStart = rb.getString("start");
				sStop = rb.getString("stop");
				sReset = rb.getString("reset");
			} catch (MissingResourceException e) {
				System.out.println("Missing Resource: "+e.getMessage());
				sStart = "Start";
				sStop = "Stop";
				sReset = "Reset";
			}
		} else {
			sStart = "Start";
			sStop = "Stop";
			sReset = "Reset";
		}
		// Load parameters needed for creating the main panel.
		sParam = this.getParameter("nballs");
		if (sParam != null) {
			try {
				nBalls = Integer.parseInt(sParam);
			} catch (NumberFormatException e) {
				nBalls = 40;
				System.out.println("nballs should be an integer number of balls in the box.");
			}
		} else nBalls = 110;
		sParam = this.getParameter("nBigballs");
		if (sParam != null) {
			try {
				nBigBalls = Integer.parseInt(sParam);
			} catch (NumberFormatException e) {
				nBigBalls = 40;
				System.out.println("nBigballs should be an integer number of balls in the box.");
			}
		} else nBigBalls = 10;
  #4  
Old 26-Dec-2007, 20:20
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 959
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Extending the array elements


Can you possibly post more code, as 'num' is not used in the init() call? [If not, that's ok, some don't, but know that assistance might be limited]

There is nothing obvious in what was given, so far. [it's not clear from the two code blocks provided in post #3 are part of the same class (or not) because some of the declarations [i.e. Scope, and the double arrays] in the first part are not in the second, init() part].

Also, it's not clear what the animateThread, start, stop, or the run function(s) might be doing -- assuming that any of them are used.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 14-Jan-2008, 21:34
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Re: Extending the array elements


Hi,

Been a while. Somehow, the problem solved itself. Thanks TurboPT.

The code expanded by the day, and now I am faced with another problem which is a frequent one amongst Java programmers.

Exception in thread "Thread-3" java.lang.OutOfMemoryError: Java heap space

I have googled to find what the rest have to say about this error, here is one:
"On 4/28/06, Gary E. Daniels <gdaniels@xxxxxxxxxxx> wrote:
I've run the Kermow program to transform the files in a directory and it
works on the 1st two files in my directory, but then I get the following
error messages:

"Exception in thread "Thread-3""
"java.lang.OutOfMemoryError Java Heap Space"

When I work on just a single file there is no problem. Any suggestions on
correcting this error? Thanks.
Try increasing the amount of memory available to the JVM (if you
running it using the included run.bat file alter the -Xmx value in
there, for example -Xmx1024)

It's odd though... how big are your input files? (mail me back
directly, or use the kernow mailing list as this is off-topic for
xsl-list)

cheers
andrew"

Does anyone have any idea which JVM file he is talking about? I cannot find any run.bat file, the one where the -Xmx is found. I saw a lot of JVM files in the Java folder C:\Program Files\Java\jdk1.6.0_02. I don't see anything that helps.

Thanks again.
  #6  
Old 15-Jan-2008, 18:24
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 959
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Extending the array elements


Quote:
Originally Posted by Blase
Somehow, the problem solved itself...
Maybe not. It appears the problem has only grown. That is the same thread# mentioned in a prior post.

Possibly you might just have a memory leak issue?
Check this, and this, and there is more!, just Google the last portion of that error: java.lang.OutOfMemoryError: Java heap space
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #7  
Old 15-Jan-2008, 22:38
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Re: Extending the array elements


Thanks Turbo, I really appreciate your help.
  #8  
Old 15-Jan-2008, 22:54
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Re: Extending the array elements


Thing is, how do I set
"java -Xms<initial heap size> -Xmx<maximum heap size>" in TextPad. Or should this be set somewhere else? I have no idea at the moment.
  #9  
Old 16-Jan-2008, 05:35
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 959
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Extending the array elements


To add parameters to java.exe in Textpad:

Configure->Preferences->Tools->Run Java Application

There's a 'Parameters' textbox where additional parameters can be specified.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #10  
Old 16-Jan-2008, 13:43
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Re: Extending the array elements


I did something like the attached file, because I am running applet. Errors abound...

Code:
load: class BrownianAppletjava -Xms32m -Xmx128m.class not found. java.lang.ClassNotFoundException: BrownianAppletjava -Xms32m -Xmx128m.class at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:183) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:127) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:626) at sun.applet.AppletPanel.createApplet(AppletPanel.java:779) at sun.applet.AppletPanel.runLoader(AppletPanel.java:708) at sun.applet.AppletPanel.run(AppletPanel.java:362) at java.lang.Thread.run(Thread.java:619) Caused by: java.io.FileNotFoundException: C:\MTH 9903 Capstone Sylvain\Capstone\BrownianAppletjava - Xms32m -Xmx128m\class.class (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at java.io.FileInputStream.<init>(FileInputStream.java:66) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161) at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:295) at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:44) at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:173) at java.security.AccessController.doPrivileged(Native Method) at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:170) ... 8 more
Attached Images
File Type: jpg applet.JPG (40.5 KB, 6 views)
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort in C++ alphabetically wilen C++ Forum 5 20-Apr-2007 14:43
1-D array jack999 C Programming Language 16 16-May-2006 12:38
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 19:31
Object Oriented Programming? jake_jeckel C++ Forum 8 30-Oct-2005 12:25
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 21:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:23.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.