|
Amusingly you can go the other way around very easily. If you're on *nix you might be able to write a little plugin for your window manager to forward the necessary event info to a Java application.
|
# ? Aug 15, 2011 21:29 |
|
|
# ? Jun 12, 2024 10:51 |
|
I'm only a relative noob myself - but isn't this pretty much exactly what enum types are for? That is, they store a set of fixed constants (i.e. tank weight, speed etc) and will allow him to do stuff like:code:
code:
code:
iam fucked around with this message at 21:50 on Aug 15, 2011 |
# ? Aug 15, 2011 21:48 |
|
I'm trying to write a command to a device and read a response through an ethernet-serial hub, and I get the following error: java.net.socketexception: Software caused connection abort: socket write error I know this is only tangentially related to Java since it seems to be a networking issue, but I was still hoping someone might have experienced this or know anything about it. The odd thing is that this error occurs if I try to communicate with the device once every two minutes, but not if I do it every minute instead. I would appreciate any insight into this problem.
|
# ? Aug 16, 2011 02:54 |
|
The fact that it works if you poll the device more often suggests that the connection is being closed due to not having any traffic. How exactly are you communicating with the device?
|
# ? Aug 16, 2011 03:10 |
|
Jabor posted:The fact that it works if you poll the device more often suggests that the connection is being closed due to not having any traffic. The device is connected to a 8-port serial hub via RS232, and the hub is connected to the computer via ethernet cable. I use Socket(IP Address, port) to connect, then basic InputStream and OutputStream to talk to it. I keep the connection open and communicate with it during each iteration of a loop in a thread. I'll have to be dig around in the serial hub configuration to see if there is an actual setting that causes port closure due to lack of activity, but regardless if what you mentioned is the problem, would setting setKeepAlive(true) on the socket be sufficient to prevent closure? Hidden Under a Hat fucked around with this message at 03:20 on Aug 16, 2011 |
# ? Aug 16, 2011 03:16 |
|
Hidden Under a Hat posted:I'll have to be dig around in the serial hub configuration to see if there is an actual setting that causes port closure due to lack of activity, but regardless if what you mentioned is the problem, would setting setKeepAlive(true) on the socket be sufficient to prevent closure? "Try it and see" would be my recommendation. It does seem like that is the sort of problem which setKeepAlive(true) would fix...
|
# ? Aug 16, 2011 03:28 |
|
Has anyone any experience of using RXTX (the serial comms library) in Java? I'm using it to talk to some RFID readers I've got as part of my MSc project, but sending/writing data is a real pita. So at the moment I have a thread (x) that's started when a write wants to be carried out. That then starts another thread (y) which does the actual writing. This allows me to sleep thread x to control the timing of writes. The problem with this method is that I have to pause for 500msec at the start of the thread to ensure that the last thread has finished writing - obviously this doesn't bode well when scaling up to have a dozen or more RFID readers. I've tried unsuccessfully to reduce the wait - any smaller than 500msec and writing becomes unreliable (at 0msec it just doesn't work). If I don't do this, from what I can tell, the writes interrupt each other - i.e. writes are carried out simultaneously and things break badly. What I want is a way of writing only when I know the previous transmission has successfully been sent. (I've just had a thought - would using different output streams work/make a difference?) Anyone with any experience with playing with serial/RXTX got any advice?
|
# ? Aug 17, 2011 00:53 |
|
Is there any reason why you can't just have each thread grab a lock when it starts writing and release it when it's done?
|
# ? Aug 17, 2011 02:23 |
|
I've used the RXTX library a bunch, but I'd say the same thing as Contra Duck. Just synchronize the method doing the writing, or acquire a lock, or put writes in a shared queue to be written serially, or something.
|
# ? Aug 17, 2011 03:13 |
|
Okay cheers - concurrency is not my strong point tbh, I'll do some reading and see what I can come up with!
|
# ? Aug 17, 2011 08:57 |
|
Maybe I am misunderstanding something but are you recycling the same output stream for each thread?
|
# ? Aug 17, 2011 15:28 |
|
I'm having a strange problem with multicast sockets. After starting and stopping senders and receivers a few times, the receiver silently fails (no error, but never receives). The receiver shows up when I run netstat -bano. This happens on two Windows 7 machines.code:
code:
|
# ? Aug 17, 2011 17:01 |
|
I figured it out (at least I haven't been able to reproduce the problem again). Apparently the receiver was picking a network interface at random. The fix was to modify the receiver from:code:
code:
|
# ? Aug 20, 2011 00:29 |
|
Abrahamsen posted:Problem:
|
# ? Aug 20, 2011 03:55 |
|
I am confused about this method:code:
|
# ? Aug 20, 2011 12:05 |
|
slyo posted:I am confused about this method:
|
# ? Aug 20, 2011 13:05 |
|
^^^^^ true, still not really what it's supposed to do I guess.slyo posted:I am confused about this method: Yes it does. The first semicolon is misplaced, an else -> return true; is also missing.
|
# ? Aug 20, 2011 13:05 |
|
it should just be return s.startsWith("/"); or to make it unreadable and also throw a better exception, return Objects.requireNonNull(s, "Line must not be null.").startsWith("/")
|
# ? Aug 20, 2011 13:09 |
|
ShardPhoenix posted:This whole concept seems a bit complex/over-abstract for an inexperienced programmer making their first game. Why not sure just normal classes/interfaces? I have made games before, these have been in AS3 and quite basic as they have mostly been tests to teach me about interacting with a data acquisition device. I wanted to do something more elaborate and expandable. So I got hooked on the idea of having entity / component relationships in a very modular way. It IS very complex and over-abstract for an inexperienced programmer like myself, but I hope the challenge will help me learn a lot (already has) and hopefully let me exercise better programming practice. Progress is slow though, as I'm self-taught and most of my problems are easily solvable by those with a better understanding of java, but hinders me because I have to spend time searching for answers to simple (or not) questions like "what is a hashmap? or when do I use interfaces?".
|
# ? Aug 20, 2011 15:06 |
|
Aleksei Vasiliev posted:it should just be return s.startsWith("/"); Wow, I never read about this feature before. Seems really useful. Too bad my workplace is using ancient versions of Java for no good reason. It's not like we have apps that rely on specific hacks to make them work, one of the devs just refuses to upgrade to new versions.
|
# ? Aug 20, 2011 18:26 |
|
Ensign Expendable posted:Wow, I never read about this feature before. Seems really useful. Too bad my workplace is using ancient versions of Java for no good reason. It's not like we have apps that rely on specific hacks to make them work, one of the devs just refuses to upgrade to new versions. Well this one is only in Java 7, so that's going to take a while anyway. Even the stable version of Eclipse doesn't support Java 7 yet (although I think various betas do).
|
# ? Aug 20, 2011 18:58 |
|
You only need 1.5 for that AFAIK, just stick this in a utility class:code:
|
# ? Aug 20, 2011 19:10 |
|
Please someone help me with a remedial-level question. I'm trying to get a String[] from an ArrayList<String> but I'm getting some weird messages: code:
code:
I'm aware I've probably done something very simple wrong but I can't for the life of me work out what it is. Anyone? edit: Worked it out, thank you, please feel free to ignore or heap scorn as desired. chippy fucked around with this message at 17:04 on Aug 23, 2011 |
# ? Aug 23, 2011 16:48 |
|
chippy posted:Please someone help me with a remedial-level question. This works as long as result declared as a String[]. Edit: added a 0 to make this compile code:
code:
baquerd fucked around with this message at 17:08 on Aug 23, 2011 |
# ? Aug 23, 2011 16:57 |
|
Having a really stupid problem that I can't figure out. I'm hoping it's completely dumb and that I'm dumb. I have a TreeSet, and I insert 10 objects into it. When I then print the contents, there are only 4 items in the set. This is basically the class I'm using. code:
code:
|
# ? Aug 23, 2011 20:33 |
|
Kilson posted:Having a really stupid problem that I can't figure out. I'm hoping it's completely dumb and that I'm dumb. Do you have a debugger? Step into your inserts and see what happens.
|
# ? Aug 23, 2011 20:55 |
|
You should read up on the Comparable interface. Your defined natural ordering is not consistent with equals. Here's a hint: You're getting four objects back. You have four distinct values for extensionCode.length() as referenced in compareTo.
|
# ? Aug 23, 2011 20:58 |
|
Lysidas posted:You should read up on the Comparable interface. Your defined natural ordering is not consistent with equals. *sigh* I read that earlier, but I kind of stopped after the part where it said: Comparable posted:It is strongly recommended (though not required) that natural orderings be consistent with equals. I thought it was just recommended for some sort of ivory-tower reason, not because the difference would have real effects. Thanks for pointing out my failure to RTFM.
|
# ? Aug 23, 2011 21:03 |
|
Kilson posted:I thought it was just recommended for some sort of ivory-tower reason, not because the difference would have real effects. That "recommended, but not required" bit is basically a promise that if something requires Comparable objects then that something is not going to mix in some calls to .equals(), even though it technically could.
|
# ? Aug 23, 2011 22:18 |
|
Kilson posted:This is basically the class I'm using.
|
# ? Aug 24, 2011 00:54 |
|
Aleksei Vasiliev posted:why are you using ternaries inside if statements Those were methods generated by the IDE.
|
# ? Aug 24, 2011 16:11 |
|
I'm not sure if it belongs in coding horrors, but how doescode:
From context, it seems to be testing if string1 == "", though no idea why that was used instead of null.
|
# ? Aug 25, 2011 16:06 |
|
AlsoD posted:I'm not sure if it belongs in coding horrors, but how does code:
Also, don't use == for comparing Strings ever unless you are testing reference identity. baquerd fucked around with this message at 16:15 on Aug 25, 2011 |
# ? Aug 25, 2011 16:12 |
|
baquerd posted:Also, don't use == for comparing Strings ever unless you are testing reference identity. I've been writing Java almost every day for months and this screws me over at least once a week. I'm stupid. (Most of my experience is in Python)
|
# ? Aug 25, 2011 19:01 |
|
I'm pretty sure that the compareTo(" ") was done because he'd heard about the "==" thing, but didn't know about equals(String). The earlier method was basically find a string, else return "" and so I think he wanted to check for failure. I don't know why he didn't just have it return null for failure though.
|
# ? Aug 25, 2011 19:07 |
|
AlsoD posted:I'm pretty sure that the compareTo(" ") was done because he'd heard about the "==" thing, but didn't know about equals(String). The earlier method was basically find a string, else return "" and so I think he wanted to check for failure. I don't know why he didn't just have it return null for failure though. This is what you are describing: code:
|
# ? Aug 25, 2011 19:10 |
|
I have a question about using instanceof. I googled a bit and it seems that using instanceof is considered bad form. I can't think of another easy way to do what I'm trying to do though. I basically have a tabbed pane that a user can dynamically add a choice of two different Instrument classes that extend JPanel which each have a different set of fields/selections. They can add as many instrument panels as they want. When the user hits accept, I basically want my program to go through each added panel and call a method called getSettings() from each panel to get the user-entered settings. The problem is the program doesn't know which Instrument class each panel actually is. Here is what I have so far:code:
|
# ? Aug 30, 2011 21:35 |
|
I have never heard of instanceof being a bad idea. You could do something likecode:
|
# ? Aug 30, 2011 21:42 |
|
You could organize your code differently to separate semantic content, like the settings available for various components, from the structure of your UI. Failing that, you could at least make an interface with a getSettings() method and test for that rather than N individual subclasses.
|
# ? Aug 30, 2011 21:44 |
|
|
# ? Jun 12, 2024 10:51 |
|
Using it for the method you describe cries that you should implement an interface that Instrument classes subclass to provide that method. It is considered bad form when you are using it to basically serve as the old dreaded C 200 line if..else if.. statement. Basically, used too liberally it can point to issues with design. Now that I've said that, it is important to remember that instanceof is the only way to handle certain situations (especially when dealing with code older then Java 5). People who automatically dismiss it as bad, are the same people who think dynamic_cast in C++ is terrible.
|
# ? Aug 30, 2011 21:51 |