Sam Smith

Greenhorn
+ Follow
since May 31, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sam Smith

Hi all,

I'm writing a small class that part of a much larger application that I can't modify. The class is supposed to open a java program and return a JPanel representing the program's output window. That JPanel will then display in the main program's JFrame.

Here is a snippet of my code:

This code works fine if I create a little main method in this class which gets this JPanel and sticks in in a new JFrame. Nothing wrong there.

However, when the main program tries to get the JPanel to place it in the JFrame, I get:

Where the line referenced at the bottom of that is


Reading through some tutorials, I see that if getJPanel() were called using InvokeLater, the problem should be fixed(?). However, I can't change the code that calls this method. I tried putting the code above in a Runnable, and calling InvokeLater on it, but I get the same error.

Anyone have any clues as to how I can fix this, without changing either the code that calls this method or the WaveInterferenceApplication?

Any help would be much appreciated,
Thanks!
Sam
Well, I wasn't able to find out what the bug is in the code above, but I do have some new code that appears to work, Posting here for anyone that comes across this with the same problem:

17 years ago
Hi all,

I have a program that worked fine when I was using the Java 1.5 libraries, but now that I've changed it to 1.4.2 (Java HotSpot) I get an odd error that I haven't been able to fix.

I want to get my mouse cursor to disappear when it's inside a JFrame. The short program below replicates the problem on my computer. In it, I have two alternate ways of hiding my mouse. Both options work fine when I set my libraries to be 1.5. Using 1.4.2, they don't.

The first option simply fails to hide the mouse.
The second option again fails to hide the mouse, and also shows the following error message:


The error message doesn't terminate the program, only appears when I move my mouse over the frame, and repeats for as long as I move my mouse.

I'm using a Mac. A friend was unable to get the problem to show up using a PC, so it might be a platform-specific problem.

Does anyone know if either 1) there's a bug in my code which is easily changeable, or 2) if there's another way of hiding a mouse cursor that will work for me?

Any help would be very much appreciated!

--------

SSCCE:


[ December 07, 2006: Message edited by: Sam Smith ]
17 years ago

Originally posted by Joe Ess:
Slow performance in your case may have something to do with your program managing 1,500,000 independent organisms.



Well, that's unavoidable.



Physically breaking it? No.
Bringing it to a crawl and possibly crashing it? Yes. As above, total up the memory requirements of all running processes and don't let that number exceed physical memory.



Well yes, I meant break it metaphorically - crash it. But, with an otherwise idle Windows XP machine (except for backgroup processes), 512 MB RAM, 7.2 GB free space on my hard drive, it shouldn't complain too much if I, say, use -Xmx512m, would it? Just wondering in case I start needed to run even bigger experiments


... but anyway, I don't think it would come to that. Thanks very much for your help.
[ June 10, 2005: Message edited by: Sam Smith ]
18 years ago
Oh wait java -Xmx256m works.

So is there any way to set things so I don't have to use this each time?

And if I increase this further will the program run any faster (it's really slow at such numbers)? Is there a point that I shouldn't exceed for fear of breaking the computer?
[ June 10, 2005: Message edited by: Sam Smith ]
18 years ago

Originally posted by Jeffrey Spaulding:
Did you increase the memory footprint of Eclise?

Run eclipse.exe -vmargs -Xmx256m (or whatever your machine can give you)

Does it work when running outside of eclipse

If not start your vm with a bigger heap

http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/java.html



Hmmm, it doesn't work outside of Eclipse, though the error message is a little more detailed:

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

I'm not certain where in the link you gave me it has an option for increasing the heap, so I haven't been able to test that yet. Also, is it not possible to request more space from inside the code?

Thanks
18 years ago
Hi,

I'm trying to run a genetic algorithms experiment, and keep getting a java.lang.OutOfMemoryError error.

This happens when I'm trying to populate my world to set up the experiment.

I'm trying to create 50 environments, each of which contain an array with 1000 organisms, each of which contain an array with 10 neurons, each of which contain (on average) an array of 3 random weights (floats).

I'm therefore basically trying to create 50*1000*10*3 = 1,500,000 floats.

The program crashes after creating about 25 environments, so 750,000 floats. At smaller numbers the program doesn't crash.


So a couple of questions: 750,000 floats doesn't sound like a huge amount for a program to create. Is this enough to get an OutOfMemory error?

Is it likely that my datasets are inefficient? Arrays should be pretty light-weight, right? I initialize them once only, with the correct size.

To be able to do further testing, is there any way to back-trace the OutOfMemory error? I'm using eclipse, and, while you can click on many errors to see where they're coming from, I can't with this one.


Any advice or recommendations would be much appreciated.

Thanks,
Sam
18 years ago

Originally posted by Stan James:
Instead of making Evolution extend Thread you can make it implement Runnable. The code inside probably won't change one bit, but we can start things a little differently and keep one Evolution around all day.

Note that we didn't try to restart a Thread. You found that won't work. Instead we ran a brand new thread with the same Evolution.

See if that will work for you. If not, post fresh code and we'll try again.

[ June 09, 2005: Message edited by: Stan James ]




Yayy!!!

No more questions about this, I prormise. Thanks very much all.
18 years ago
So I'd have to create a brand-new instance of the class?

Hmmm... that doesn't sound possible. That class is the very first thing that gets created - everything else depends on it being around.

Would it still work if I switched the thread class to being the gui in my example above, instead of the EvolutionEngine as was suggested?

If not, I guess I can live with just running the experiment once, and restarting the program if I need to run another... Actually, that's a question that I've never wondered about: how can I restart the program from within it? Can I just call MeGA.main(String[] args) from within some random method?
[ June 09, 2005: Message edited by: Sam Smith ]
18 years ago
Wait, not all is peachy.

The run() method works great, and threads well with the progress bar.

However, I can't seem to start it up again after the run() method has completed (i.e. pressing "run" on my gui, which calls engine.start() does nothing).

The method run() has definately quit, and, as a test, I threw in a stop() command for good measure. Nothing.

When I switch the threaded method for my original method, everything works fine (except it doesn't thread), so it's obviously something to do with the thread.

Any suggestions?

Thanks!
18 years ago
Hey wait, that is all it took!

Thanks!
18 years ago
So the progress bar doesn't need to be in its own thread? Or, when calling engine.start() it creates two threads automatically?

Either way, that's all I have to do? Wow, tutorials make things so complicated.

I can't test it now, have to run, but assuming it works, thanks very much.
18 years ago
I've tried to understand threading from ten different tutorials, but it makes my head spin because all the tutorials include so much extra stuff that I don't know what's important.

I've got a piece of code here with a gui, which contains a progress bar. I'd like the progress bar to update in a timely fashion, but not take up much of the main thread's recources.

I've cut the code down to it's barest minimum. I'd really appreciate it someone were to tell me how to edit this code so that it implements threading? Thanks so much!


[ June 09, 2005: Message edited by: Sam Smith ]
18 years ago
Looks like they don't have Works Spreadsheet (.xlr), but thanks for the handy reference. Bookmarked.
18 years ago
Alright, I'll look through that. Thanks, Steven.

Thanks for the welcome, Ernest, and name changed... though I'm not entirely sure why a false-sounding name such as "Sam Smith" is better than not giving my last name, but no matter.
[ May 31, 2005: Message edited by: Sam Smith ]
18 years ago