|
when you run your program you run it using java.exe .... some options like class path, and path to your main .class file. just use -Xmx1000m in there, or if you are using some IDE you can go into its options and find a field that says something like "command line arguments" for when you run your project. just put -Xmx1000m there. For exception, you must have (or should add at right place) something like code:
|
# ? Nov 28, 2008 22:26 |
|
|
# ? May 11, 2024 13:12 |
|
Really common beginner error, never use == on Strings. Use .equals() Edit: as in if (choice1.equals("yes") || choice1.equals("Yes"))
|
# ? Nov 28, 2008 22:33 |
|
JulianD posted:I checked to see that's the problem after your suggestion, but I don't think that's it. I added this to my program to see how much memory I had before and after calling the last method of my program: If you want to see how much ram is available to your vm you should run jstat on the vm running your program. You can see how much ram is available to each object space (eden, survivor 0 and 1, old gen and permanent gen) over the duration of your program's lifetime. It's a really awesome tool and comes with the jdk.
|
# ? Nov 28, 2008 22:51 |
|
BELL END posted:Really common beginner error, never use == on Strings. Use .equals() I would like to expand on this, saying that this is because == compares where reference points to, not the actual contents of objects. Since java has no operator overloading you have to use .equal for String's comparisons, since .equals will actually check the contents of Strings, and == only checks if its same object. You can have String a = "zomg" and String b = "zomg". However if JVM decides to store them in different locations in memory, then a==b will return false.
|
# ? Nov 28, 2008 22:55 |
|
If you want to check out your memory usage, you should chek out Jconsole (should be in your jdk's bin). I just finished doing some work with it, and using a heap analyzer (MAT for Eclipse) to figure out why our software was running out of memory.
|
# ? Nov 29, 2008 02:19 |
|
Gah, now I have a problem entirely separate from the programming. I stupidly left Dr. Java running when I hibernated my computer, and now I'm getting the error, "Could not create the Java Virtual Machine". I've completely uninstalled and then reinstalled all of my Java applications, but the error still occurs each time I try to open Dr. Java to continue working on my programs. The best suggestion I've found so far is to reinstall my OS completely (which seems like a pretty lovely suggestion, honestly). Any better ideas out there?
|
# ? Nov 29, 2008 02:42 |
|
JulianD posted:Gah, now I have a problem entirely separate from the programming. I stupidly left Dr. Java running when I hibernated my computer, and now I'm getting the error, "Could not create the Java Virtual Machine". I've completely uninstalled and then reinstalled all of my Java applications, but the error still occurs each time I try to open Dr. Java to continue working on my programs. The best suggestion I've found so far is to reinstall my OS completely (which seems like a pretty lovely suggestion, honestly). Any better ideas out there? Try to edit the options and change the path that points to your JDK install? Or use Eclipse, JBuilder, or NetBeans
|
# ? Nov 29, 2008 02:55 |
|
BELL END posted:Really common beginner error, never use == on Strings. Use .equals() You can go one step further and replace this with code:
|
# ? Nov 30, 2008 02:48 |
|
Okay so this sounds like a pretty dumb problem but I have a generic classe that is defined in a lot of places in my program, can I use a constant (or something else?) to define the generic type (it is subclassed to Numbers)? I want to be able to switch around from integers to doubles to test things out.
Strong Sauce fucked around with this message at 09:40 on Nov 30, 2008 |
# ? Nov 30, 2008 09:37 |
|
Strong Sauce posted:Okay so this sounds like a pretty dumb problem but I have a generic classe that is defined in a lot of places in my program, can I use a constant (or something else?) to define the generic type (it is subclassed to Numbers)? I want to be able to switch around from integers to doubles to test things out. You want generics: http://sys.cs.rice.edu/~sethn/wordpress/?p=6
|
# ? Nov 30, 2008 12:08 |
|
dancavallaro posted:You can go one step further and replace this with Even better is code:
|
# ? Nov 30, 2008 15:06 |
|
Mill Town posted:You want generics: http://sys.cs.rice.edu/~sethn/wordpress/?p=6 Eh? My problem was with generics. But anyways I figured out that you can't define a constant for the generic type.
|
# ? Nov 30, 2008 18:28 |
|
Strong Sauce posted:Eh? My problem was with generics. But anyways I figured out that you can't define a constant for the generic type. You want AspectJ. Except no one really wants AspectJ, as far as I can tell. My question, which is less Java related and more "data structures oh god why did I take this class this semester": implementing a splay tree. How strictly is one supposed to follow the rules of splaying every time you access a node? For example, I'm writing a method to return an array representation of the node-keys from an inorder traversal of the tree. Am I supposed to splay after visiting each node ? Or do I only splay after searching expressly for a specific key?
|
# ? Nov 30, 2008 19:05 |
|
Emo.fm posted:You want AspectJ. Except no one really wants AspectJ, as far as I can tell. The purpose of splaying is to optimize future accesses to similar data, which isn't meaningful for full-tree operations. Your assignment might say differently, but I've implemented a fair number of splay trees, and none of them have ever modified the tree during a full-tree operation. rjmccall fucked around with this message at 23:03 on Nov 30, 2008 |
# ? Nov 30, 2008 23:00 |
|
I'm new to java and trying to learn IO and Exceptions, but after hours I can't figure out what i'm doing wrong. This is my first time using NetBeans. I'm making a search program that opens and looks for a word in text files in a folder. For some reason I don't see a flaw in my logic, but there must be, since it stops scanning a directory and pops out an Exception. Any insight to see what i'm doing incorrectly?code:
|
# ? Nov 30, 2008 23:16 |
|
Maybe someone here can help me with an issue I'm having. I'm writing a blackjack game using Swing. I have a loop going through all of the players and commencing their AI turns if they aren't human. If they are human, I don't know how to block my loop until a button press occurs. I hope this makes sense. Anyone have any familiarity with this? EDIT: I'm a loving imbecile. Note to self: Just don't use loops at all, moron. Love, Me P.S. -- There's chicken in the fridge. Help yourself. KyPeN fucked around with this message at 01:16 on Dec 1, 2008 |
# ? Dec 1, 2008 00:47 |
|
Slainhobo posted:I'm new to java and trying to learn IO and Exceptions, but after hours I can't figure out what i'm doing wrong. This is my first time using NetBeans. I'm making a search program that opens and looks for a word in text files in a folder. For some reason I don't see a flaw in my logic, but there must be, since it stops scanning a directory and pops out an Exception. Any insight to see what i'm doing incorrectly? Knowing the type of the exception, the line it occurred on, and the stack trace will go a long way to helping someone answer that question. Or I could run that code myself, but that won't work either since it's a snippet and not the whole application. I'm certainly not going to simulate it in my head.
|
# ? Dec 1, 2008 02:20 |
|
I'm having some trouble using the PriorityQueue class. It's not keeping things in the order it should be, and I'm not sure why. I have a PQ of Nodes, which implements comparable:code:
What am I doing wrong here? edit: I figured out what order it's putting them in - the order in which they were created. Eclipse labels each object you create and gives it an ID number and apparently the PQ is sorting by this. double edit!: As I said, I'm using Eclipse, and it's doing something strange. I'm getting different output depending on if I run it or debug (run with breakpoints) it. Both methods are running in the same place with the same arguments, but they spit out different stuff. Who ever heard of such a thing. Clanpot Shake fucked around with this message at 03:43 on Dec 1, 2008 |
# ? Dec 1, 2008 03:02 |
|
SuperGoon posted:Even better is I must be missing something, why is this better? Isn't this equivalent to the other method?
|
# ? Dec 1, 2008 04:27 |
|
Idran posted:I must be missing something, why is this better? Isn't this equivalent to the other method? What happens when choice1 is null in the original example? That convention does a null check and an .equals type check all in one.
|
# ? Dec 1, 2008 04:55 |
|
SuperGoon posted:What happens when choice1 is null in the original example? Oh, you're right, I didn't even think about that. I always forget to check for null until it ends up biting me down the line, so that didn't even occur to me. Cool, I'll have to remember that convention, then.
|
# ? Dec 1, 2008 06:51 |
|
Clanpot Shake posted:Problems with PriorityQueue... According to the docs, it looks like you need to pass a Comparator in the constructor of the PriorityQueue; It's not enough to just have your elements implement Comparable. I think the whole thing might boil down to: code:
Outlaw Programmer fucked around with this message at 07:58 on Dec 1, 2008 |
# ? Dec 1, 2008 07:55 |
|
Outlaw Programmer posted:I think the whole thing might boil down to:
|
# ? Dec 1, 2008 16:58 |
|
Idran posted:Oh, you're right, I didn't even think about that. I always forget to check for null until it ends up biting me down the line, so that didn't even occur to me. Cool, I'll have to remember that convention, then.
|
# ? Dec 1, 2008 17:05 |
|
More PriorityQueue nonsense: This is the Node comparator used by my PQ: code:
Anyway, The queue isn't popping off items in the correct order. For the life of me, I can't figure out what order it IS popping them off in. It's not the highest or lowest total, that's for sure. Is there a way to force the queue to reorder itself, or is it decided what item to pop off when poll() is called? Is it okay to dynamically add and remove items from a PQ and have it maintain order?
|
# ? Dec 2, 2008 04:07 |
|
I have a question about WizardPage's with jface, but I think it might be more general to dialogs in Eclipse SWT. I am finding if I try to change graphical elements in the WizardPage, they don't get updated. So let's say I have a button that I click and a listener attached. I can see the listener is running through debug print statements. I try to setText() on the button, yet I don't see the button reflect to change the new text. I assume redraw events aren't making it back properly, but I don't know how to link it all up. redraw() commands from the handler aren't doing the job. Any ideas? Edit: Figured it out. Holy poo poo. You have to spin off Runnables that ask the shell to redraw. I guess some of that has to do with the wizard page being in a dialog, so the message handling is all internal. Rocko Bonaparte fucked around with this message at 19:30 on Dec 2, 2008 |
# ? Dec 2, 2008 04:43 |
|
Clanpot Shake posted:Is there a way to force the queue to reorder itself, or is it decided what item to pop off when poll() is called? Clanpot Shake posted:Is it okay to dynamically add and remove items from a PQ and have it maintain order? It might be time to post more code...
|
# ? Dec 2, 2008 09:47 |
|
Outlaw Programmer posted:According to the docs, it looks like you need to pass a Comparator in the constructor of the PriorityQueue; It's not enough to just have your elements implement Comparable. This is incorrect; if you fail to provide a comparator, it will fall back on the natural ordering, which assumes that the objects implement Comparable. Clanpot, is it too much to ask to post the fulltext of Node as well as your insertion/removal code? I think you must be making some very silly mechanical error. Outlaw Programmer posted:
This is probably correct here, but I'm under contract with the PL Pedant's Union to observe that this relies on particular assumptions about the range of getTotal() and that people shouldn't get in the habit of using this shortcut without thinking about it.
|
# ? Dec 2, 2008 12:11 |
|
Clanpot Shake posted:... Are you sure this does what you think it does? i.e. (int) (6.99999997 * 10) = 69 but (int) (7.0000001 * 10 ) = 70. For positive numbers, (int) is equivalent to floor, not the nearest integer.
|
# ? Dec 2, 2008 14:56 |
|
Brain Candy posted:Are you sure this does what you think it does? i.e. (int) (6.99999997 * 10) = 69 but (int) (7.0000001 * 10 ) = 70. For positive numbers, (int) is equivalent to floor, not the nearest integer. Right then, here's my Node code: code:
code:
edit: I think I fixed it. The problem was that I was adding Nodes to the PQ before modifying them, which threw off the priority order (even though the nodes in the queue themselves were modified). Clanpot Shake fucked around with this message at 20:30 on Dec 2, 2008 |
# ? Dec 2, 2008 17:31 |
|
Clanpot Shake posted:edit: I think I fixed it. The problem was that I was adding Nodes to the PQ before modifying them, which threw off the priority order (even though the nodes in the queue themselves were modified). Yes, that's definitely the problem; you're breaking the data structure's invariants. I should have considered that before asking you to post your code. Just some general notes:
|
# ? Dec 2, 2008 22:46 |
|
rjmccall posted:Just some general notes: rjmccall posted:Why is closed a priority queue? The only operation you perform on it is membership testing; a set would be much faster, but in this case you could get away with a flag on the node. The other two things are good points, but I don't have any specific response to them. There is one thing you missed though (I did too, and I'm still working on it). Node implements equals, but not hashCode, which it's supposed to. Because it doesn't, closed.contains(n) (contains calls equals()) won't function properly, and some nodes will be explored more than once. As I said, I'm still working on fixing this.
|
# ? Dec 3, 2008 02:01 |
|
Clanpot Shake posted:Node implements equals, but not hashCode, which it's supposed to. Because it doesn't, closed.contains(n) (contains calls equals()) won't function properly, and some nodes will be explored more than once. As I said, I'm still working on fixing this. Actually, I would guess that your equals and hashCode methods are already de facto consistent; the requirement is just that A.equals(B) implies (A.hashCode()==B.hashCode()), and I bet you never have two distinct nodes that are actually equal (i.e. have the same position). In fact, it looks like you'd probably have bugs if you did— priority queues certainly don't enforce set semantics on insertion. I would strongly suggest dropping back to reference-equality semanics, since distinct nodes are really distinct entities anyway.
|
# ? Dec 3, 2008 02:26 |
|
I'm trying to manipulate one of my pages to see if it catches auto voting, and I'm wondering how to go about doing this. Basically the page (javascript) has a few radio buttons with options selected, and a final radio with a blank text box for optional input. Should I write a script with Ajax to use the get/post and see If it'll accept it, or is there an easier way?Code posted:<form name="voteForm" action="thanksVote" method="POST">
|
# ? Dec 3, 2008 08:31 |
|
basic360 posted:I'm trying to manipulate one of my pages to see if it catches auto voting, and I'm wondering how to go about doing this. Basically the page (javascript) has a few radio buttons with options selected, and a final radio with a blank text box for optional input. Should I write a script with Ajax to use the get/post and see If it'll accept it, or is there an easier way? Java is not JavaScript. Try here: http://forums.somethingawful.com/showthread.php?threadid=2718078
|
# ? Dec 3, 2008 08:49 |
|
This is probably a stupid question but my teacher sucks, so here goes:code:
The book we have been using, and how I would do the add method is like this: code:
Is this some kind of industry standard and I should be doing it like that, if so why?
|
# ? Dec 4, 2008 17:00 |
|
zokie posted:This is probably a stupid question but my teacher sucks, so here goes: You don't have to use modifiers and accessors, but for a more complicated data structure those make a lot more sense to use inside the class even if you have access to actual private/protected variables inside the class. The reason is, is that add or get commands could be a lot more complex than one line. Using them from inside your own class just saves on code duplication. Also it makes your code more readable to the user trying to understand implementation of your class.
|
# ? Dec 4, 2008 17:55 |
|
zokie posted:And I can't for the love of all that is unholy understand why you would want to use the get and set methods while still in the class. What if your set method did this: code:
|
# ? Dec 4, 2008 20:16 |
|
Thanks hexadecimal and csammis, I get it now
|
# ? Dec 4, 2008 21:30 |
|
|
# ? May 11, 2024 13:12 |
|
I'm doing a Java Applet for programming class, and my applet works fine in eclipse, but as soon as I load it into a html file, it doesn't. code:
http://www.horstmann.com/oodp2/solutions/Ch8/Ex3/index.html What could be wrong?
|
# ? Dec 5, 2008 12:22 |