|
Puppet Pal Claudius posted:Is there another way to check if a rectangle is being selected? Or at least some way for my program to know which rectangle is above another? If you don't keep track of it then neither of your rectangles is above the other. If you do keep track of it then your problem is solved because you can just check which one is on top.
|
# ? Mar 12, 2011 21:13 |
|
|
# ? Jun 12, 2024 03:17 |
|
Absolutely losing it here, any ideas how I can write these results to a text file? I've spend several hours trying to get it to work and this is my last hopecode:
Schism. fucked around with this message at 21:05 on Mar 13, 2011 |
# ? Mar 13, 2011 20:54 |
|
You can only really write out characters, and sequences of characters. Thankfully, there is a built-in way to convert any arbitrary object to a sequence of characters - the toString method. Most standard-library types that you'd want to print have a reasonable implementation of it already, if you want to print out a class that you've defined then you'll need to override the default with something that's reasonable for your class.
|
# ? Mar 13, 2011 21:40 |
|
Schism: For the love of god indent your code properly.code:
|
# ? Mar 13, 2011 21:50 |
|
Dunno where else I'd ask, but does anyone do Android development or have experience with the ADK and ADK plugin for Ecplise? If this is the wrong thread, could I have a finger point in a better direction? If this is the right place, I think my problem is a simple one since I'm just starting out. So far it's been a pretty simple procedure getting Eclipse and setting it up with the Android SDK. I've got as far as being able to write this simple Hello World application, but when I compile, it starts the virtual device (Android emulator), but never displays the application. As far as I know I have everything set up correctly in Eclipse and the SDK manager. Once I know if I'm asking the right crowd or not, I can elaborate more. Thanks!
|
# ? Mar 13, 2011 22:15 |
|
Thanks guys, got it working. Shouldn't have been loving around with it at 1am last night
|
# ? Mar 13, 2011 22:48 |
|
deviler posted:Dunno where else I'd ask, but does anyone do Android development or have experience with the ADK and ADK plugin for Ecplise? If this is the wrong thread, could I have a finger point in a better direction? There is a separate thread for Android development, yes. It's not particularly active, but someone will probably help you if you have a specific question. deviler posted:...but when I compile, it starts the virtual device (Android emulator), but never displays the application. As far as I know I have everything set up correctly in Eclipse and the SDK manager. Try looking at the Console window in eclipse (this will tell you if it had a problem installing the application to the emulator) and at the LogCat window (LogCat is the tool for looking at the logs from the android device/emulator itself, so this will give you a stack trace if your program is installing right but crashing immediately or anything like that). I often find that if the emulator isn't running already when I try to run an app, Eclipse just gives up on running the app since startup takes so long. You might try running the app again once the emulator is fully loaded. If you have a real device, that's usually much more useful for testing with - the emulator is pretty slow.
|
# ? Mar 13, 2011 22:54 |
|
Hey, the problem was I just wasn't patient enough! Thanks, that was actually what was up. Also thanks for the link to the thread. I looked and looked but didn't see anything. I'm sure I'll be using it a lot as I work on more stuff
|
# ? Mar 14, 2011 00:11 |
|
deviler posted:Hey, the problem was I just wasn't patient enough! Thanks, that was actually what was up. Also thanks for the link to the thread. I looked and looked but didn't see anything. I'm sure I'll be using it a lot as I work on more stuff Yeah the emulator takes aeons to actually start up and run your program.
|
# ? Mar 14, 2011 13:57 |
|
This is a pretty simple (I think) question, since I'm pretty retarded.code:
The API says to use sort I need to implement the Comparable interface, which Dog does. But when I do that, I get an error saying "Dog is not abstract and does override abstract method compareTo(java.lnag.Object) in java.lang.Comparable" So yea, I'm trying to just alphabetize (and then display) an Array List. Not really sure what I'm doing wrong.
|
# ? Mar 15, 2011 04:42 |
|
Sab669 posted:In the for loop I just have the user enter the the data for the Dog class. When you tell the compiler that "Dog implements Comparable<Dog>" you are agreeing to implement all the methods defined by that interface. Because Comparable<T> is a generic interface you must specify what your Dog class is comparable to, and thus are obligated to implement the compareTo(T) method for the type you specify. That compiler error looks like you probably defined Dog as "Dog implements Comparable<Object>" and implemented "public int compareTo(Dog d)". When you say "implements Comparable<Object>" you are telling compiler that you are going to implement "public int compareTo(Object o)" as opposed to "public int compareTo(Dog d)". Make sure you said what you actually meant which is probably "Dog implements Comparable<Dog>".
|
# ? Mar 15, 2011 04:52 |
|
While learning Java for the first time, I had a chance to compare one of my lab assignments to the suggested solution. This is just the error-checking portion of the whole code that I have a question with. It is supposed to keep asking for an input if the input is not in the desired range.code:
code:
|
# ? Mar 16, 2011 08:46 |
|
Eflas posted:
It loops until the input gathered in the loop matches the desired input, then breaks out of the loop. As a professional, I would generally prefer and I am used to seeing the suggested version for neatness and readability.
|
# ? Mar 16, 2011 09:25 |
|
Eflas posted:As can be seen, both versions do essentially the same thing. However, the suggested version while seemingly more compact and neat, is obscure to me at first glance. Can anyone tell me how does the suggested version work? Thanks in advance!
|
# ? Mar 16, 2011 11:41 |
|
If you've read 'Loop Patterns' you'll recognize that idiom as "Loop and a Half".
|
# ? Mar 16, 2011 14:50 |
|
In my workspace right now there are 6,181 java source files and I can't find a single instance of a do/while loop. Do/while works perfectly well in your case, and you certainly wouldn't be marked down on it if you used it in an assignment, but in general the while/break idiom is more powerful so people tend to use it for everything.
|
# ? Mar 17, 2011 03:55 |
|
I was wondering if anyone could recommended me some good Java books to sharpen my skills with. I find myself having to refer back to old code that I've written previously to remember how to do the easiest of things and it's really getting old, especially since I plan on majoring in computer science when I go off to college. The only book I have right now (and I can't even find it) is the standard computer science book written by Leon Schram that was given to me when I started Computer Science 1 two years ago.
|
# ? Mar 17, 2011 08:34 |
|
Diametunim posted:I was wondering if anyone could recommended me some good Java books to sharpen my skills with. I find myself having to refer back to old code that I've written previously to remember how to do the easiest of things and it's really getting old, especially since I plan on majoring in computer science when I go off to college. The only book I have right now (and I can't even find it) is the standard computer science book written by Leon Schram that was given to me when I started Computer Science 1 two years ago. Well, it depends on what you're looking to do with Java. I personally love Effective Java, but that's more of a general book. You might prefer to read about a specific Java technology in a recipe-style book, like Spring Recipes.
|
# ? Mar 19, 2011 00:00 |
|
Java Puzzlers is also a great way to learn more about the language, attacking the issue from a different angle. The book's site has some pretty intriguing samples to try out if you think you might be interested. This book might not teach you everything you want to know, but it will expose gaps in your understanding and push you to seek out more information.
|
# ? Mar 19, 2011 04:57 |
|
MariusMcG posted:Well, it depends on what you're looking to do with Java. I personally love Effective Java, but that's more of a general book. You might prefer to read about a specific Java technology in a recipe-style book, like Spring Recipes. Thanks, I'm definitely looking for a more general Java book right now to refresh the skills that I already know. The most complicated thing I've ever put my head into was advanced swing menus. The most complicated thing I've ever written was a simple version of battleship and even that didn't work correctly so I'm definitely still looking for more basic (or what I consider to be basic?) books. Internet Janitor posted:Java Puzzlers is also a great way to learn more about the language, attacking the issue from a different angle. The book's site has some pretty intriguing samples to try out if you think you might be interested. This book might not teach you everything you want to know, but it will expose gaps in your understanding and push you to seek out more information. Sound Sound 2 Loop Sound
|
# ? Mar 19, 2011 17:01 |
|
Diametunim: I took a look at your "Loop Sound" class. First, I went through and tried to simplify it as much as possible. I've mainly removed some variables and methods you didn't use and collapsed together all the exception handling stuff. I think this makes it a bit easier to follow the logic of the code. You will also notice I restructured your main loop using "Loop and a Half" as discussed earlier. http://pastebin.com/S6yWMR6H Your approach to looping the audio seems kinda sketchy- you just keep instantiating new LoopSound objects over and over. After a little poking around, I found the Clip class, which may already do exactly what you want: http://pastebin.com/fFQEKGdR Obviously at this point you don't really need a "LoopSound" class in the first place. This approach probably buffers the entire audio file in memory, so if this poses a problem you may have to get more creative- does anyone else have much experience with audio in Java?
|
# ? Mar 19, 2011 18:00 |
|
I just want to take a moment to express ARRRGH at the ecj compiler for breaking javac's nice clean NEW-DUP-init constructor idiom. Having poo poo like DUP_X1/SWAP/etc. messing with the stack between a bunch of oddly nested NEWS and inits for who knows what silly constructor call optimizing sure makes your bytecode a bitch to instrument, so thanks, ecj.
|
# ? Mar 22, 2011 03:52 |
|
Swing has always been my weak point in Java. I need more practice, and as such I was wondering if there were any decent e-books or sites that could help.
Wronkos fucked around with this message at 23:26 on Mar 22, 2011 |
# ? Mar 22, 2011 23:04 |
|
I am trying to come up with a way to merge two 'database' files which will be contained in ~ delimited .txt format. First I want to read in a header line which is the column headers, then compare and join on common columns. However I want to implement this without the use of arrays. Does anyone have any ideas on how to approach this? I thought about implementing a hash table of some sort. DholmbladRU fucked around with this message at 03:09 on Mar 23, 2011 |
# ? Mar 23, 2011 03:02 |
|
DholmbladRU posted:However I want to implement this without the use of arrays. Uh what? Why??
|
# ? Mar 23, 2011 03:10 |
|
epswing posted:Uh what? Why?? Wouldn't that reduce scalability? If a file I am trying to read has 10million rows, the program might not be able to handle this. Could be wrong, Im not the greatest programer. DholmbladRU fucked around with this message at 03:31 on Mar 23, 2011 |
# ? Mar 23, 2011 03:14 |
DholmbladRU posted:Wouldn't that reduce scalability? If a file I am trying to read has 10million rows, the program might not be able to handle this. Could be wrong, Im not the greatest programer. I would load them as separate tables in a database like SQLite and then you can JOIN the two tables. edit: after reading how you wrote the original question it almost sounds like you are asking about a homework assignment
|
|
# ? Mar 23, 2011 04:45 |
|
Maybe you can be a bit more descriptive. What is your goal? Why aren't you bulk loading this into a relational database? How wide are your rows? How big is the file in bytes? Are you arbitrarily sorting or is it known at compile time?
|
# ? Mar 23, 2011 14:36 |
|
I'm currently working on a class for school that asks me to simulate and atm machine. While using an array of 10 accounts. The accounts only contain an id number and a balance. My issue is when I ask the user for their account number I am trying to compare it to the id (which happens to be the same number as the index of the array it's in e.g. 0-9) If it does not match any of the id numbers It should ask them to enter a valid account number. Instead it throws an ArrayOutOfIndex error, which leads me to believe that I am not actually looking at the id numbers but the array index numbers. Here is the relevant code. Let me know if you need the entire code and I'll edit it in.code:
Kamakaze9 fucked around with this message at 18:31 on Mar 23, 2011 |
# ? Mar 23, 2011 18:01 |
|
quote:if(accnum == accounts[accnum].getId()) and if I understand you right: You're checking to see if the given number, i.e. 9, is equal to array[9].getId(), which should be 9?
|
# ? Mar 23, 2011 18:10 |
|
Aleksei Vasiliev posted:
That's correct. And I figured that's where the issue was, I wanted to make sure that I was in fact looking at the id number, not the array index number, and if I am. How to make it ignore the fact that I am out of the index and just go to my else statement. Instead of closing out program. poemdexter posted:I assume all of this is within a for loop? Yes, It all seems to be working, except when I enter a number that is outside the array. Again, I can post all the code if you need me too. chippy posted:Well you could throw a try-catch around it and handle the ArrayOutOfIndex of exception that way, but you shouldn't be using exceptions for flow control. I could but then it is only looking at the array index and my goal is to compare the id number. For more realistic issue of the account numbers being different than the array index. Maybe I'm being too anal, obviously a real world wouldn't be using arrays anyway. Kamakaze9 fucked around with this message at 18:27 on Mar 23, 2011 |
# ? Mar 23, 2011 18:17 |
|
I assume all of this is within a for loop?
|
# ? Mar 23, 2011 18:19 |
|
Well you could throw a try-catch around it and handle the ArrayOutOfIndex of exception that way, but you shouldn't be using exceptions for flow control. Can't you just check if (accnum < accounts.length) and act accordingly? edit: I think we better see more of your code, I'm not sure what you're doing here. quote:if(accnum == accounts[accnum].getId()) Surely this is always going to be true, as long as you haven't gone out of range of the array? chippy fucked around with this message at 18:26 on Mar 23, 2011 |
# ? Mar 23, 2011 18:22 |
|
Aleksei Vasiliev posted:
Also, Aleksei has a point. If you only have 0-9 and someone puts in 20, your if statement will actually try to access the accounts[20] and throw an out of bounds error. Maybe: code:
|
# ? Mar 23, 2011 18:24 |
|
Also you're never going to hit case 4 there, because that switch statement won't be executed if case = 4.
|
# ? Mar 23, 2011 18:28 |
|
I see what you're saying about the case 4, I'll fix that. And now that you point it out I realize that I am always looking at a specific index. I would like to go through each one and compare just the id numbers, but I'm not sure how to go about that. Also, I have edited my first post with the full code.
|
# ? Mar 23, 2011 18:34 |
|
If someone puts in 20 as their account, you are still getting array out of bounds errors. Do:code:
code:
|
# ? Mar 23, 2011 19:01 |
|
Not quite what I wanted to do with it, but it will work and I'll use it unless I figure out how to accomplish my goal or at least how to better articulate it. Thanks for all the help. Also, is there a more specialized irc channel you use or does everyone pretty much hang out in cobol.
|
# ? Mar 23, 2011 20:52 |
|
Kamakaze9 posted:Not quite what I wanted to do with it, but it will work and I'll use it unless I figure out how to accomplish my goal or at least how to better articulate it. Thanks for all the help. People are getting caught up on the array issue, and the fact that, in this case, the array index corresponds to an id. If, for instance, the Accounts were a Collection<Account> then 1) the idea that the array index happens to also be the account id disappears, and 2) people would probably be giving you ideas for searching that collection. For instance, the most basic search, a simple linear search, would be to just loop through every Account in your collection, checking if the id you're looking for is the same as the id of the account currently being evaluated. If it is, return that account. If not, continue on until all of the accounts have been evaluated - in which case, you go to your error case of asking the user to enter a valid account id.
|
# ? Mar 24, 2011 00:40 |
|
|
# ? Jun 12, 2024 03:17 |
|
Yah, accounts with unique ids are just begging for a hashtable to be used.
|
# ? Mar 24, 2011 02:04 |