|
Do I need a method or something for the array?
|
# ? Jun 23, 2011 03:16 |
|
|
# ? Jun 12, 2024 11:55 |
|
If it's private, you do, if it's public you don't.
|
# ? Jun 23, 2011 03:18 |
|
Ah. Thanks. Accidentally got stuck putting it inside the constructor.
|
# ? Jun 23, 2011 04:05 |
|
Is there a way to read all serialized objects in a file at once? EDIT: Serialized an array of objects, but... I don't know how to get them out of the array after I deserialize it. Zewle fucked around with this message at 09:11 on Jun 23, 2011 |
# ? Jun 23, 2011 05:58 |
|
I have the following snippet of code and contractModel.getName() returns "King’s" (truncated for this example but serves the purpose) String trustName = contractModel.getName(); trustName = trustName.replace("’", "'"); For some reason this doesn't replace ’ with '. In fact it seemingly does nothing. Any ideas?
|
# ? Jun 23, 2011 12:57 |
|
Hidden Under a Hat posted:I have a question regarding using my main class with all the GUI swing components as a superclass, and a subclass which gets information from all the swing components to perform functions. Basically, my main GUI class seems way too big compared to my other classes, because not only does it have all the swing layout component initializations, declarations, and actionperformed methods, is also has all the other methods which manipulate the information I get from doing actions. I basically want to use my main GUI class as a superclass for a new subclass, so the subclass can have access to all the swing components without having to pass them to the class through a constructor. However, since the superclass is the one with the actionPerformed methods, and the subclass has all the other methods that use the information, I run into the problem of trying to call subclass methods from the superclass. What would be the best way to handle this or a better way to design this? Sorry I hate to quote my own question, but I really would appreciate any insight to this issue, even if it's to say that it doesn't matter if I have one class that is 10,000 lines long. Does that matter or should I really be finding a way to delegate some of the stuff in my main class to another class?
|
# ? Jun 23, 2011 15:08 |
|
Blacknose posted:I have the following snippet of code and contractModel.getName() returns "King’s" (truncated for this example but serves the purpose) Don't you need to escape the single quotes with a backslash?
|
# ? Jun 23, 2011 17:23 |
|
chippy posted:Don't you need to escape the single quotes with a backslash? Not in this case, he's not using the regex replaceAll() method but the individual character replace(). Most likely, the actual character you are trying to replace has a different underlying value in your character set.
|
# ? Jun 23, 2011 17:33 |
|
It looks like it's just not getting any matches. Try a .contains("`") to see if the character is being detected properly.
|
# ? Jun 23, 2011 18:01 |
|
Zewle posted:Is there a way to read all serialized objects in a file at once? When you say you deserialized it, do you mean you actually have an array of objects at the end? If that's the case, you can just loop through the array and grab each object.
|
# ? Jun 23, 2011 18:39 |
|
poemdexter posted:When you say you deserialized it, do you mean you actually have an array of objects at the end? If that's the case, you can just loop through the array and grab each object. I wrote code to generate student object, and then I added the students to an array, then serialized them (remembered to implement serialization) and save to a file, and another bit of code to read the array out of the file. I have the array that contains the students.... but I don't know how to grab them out of the array.
|
# ? Jun 23, 2011 19:45 |
|
Zewle posted:I wrote code to generate student object, and then I added the students to an array, then serialized them (remembered to implement serialization) and save to a file, and another bit of code to read the array out of the file. I have the array that contains the students.... but I don't know how to grab them out of the array. Something like this: code:
|
# ? Jun 23, 2011 19:48 |
|
Blacknose posted:I have the following snippet of code and contractModel.getName() returns "King’s" (truncated for this example but serves the purpose) Found the solution. ’ is extended ASCII character 146 and microsoft standard extended ASCII ignores a bunch of characters (127-150something?), so it needs to be escaped to the full unicode \u2019. That's 4 hours I'm never getting back. On the plus side I learnt more than I'll ever need to know about character encoding.
|
# ? Jun 23, 2011 22:22 |
|
Blacknose posted:Found the solution. ’ is extended ASCII character 146 and microsoft standard extended ASCII ignores a bunch of characters (127-150something?), so it needs to be escaped to the full unicode \u2019. That's 4 hours I'm never getting back. On the plus side I learnt more than I'll ever need to know about character encoding. I hate character encoding and actively go out of my way to avoid dealing with it. Everyone everywhere should use the same characters, this much is obvious.
|
# ? Jun 24, 2011 02:35 |
|
baquerd posted:Something like this: Do this. If you're not familiar with the syntax, all this is is a for loop that loops through each Student object in the array.
|
# ? Jun 24, 2011 20:17 |
|
I feel like this should be something simple but I haven't been able to find a solution after quite a bit of googling... is there a way to add a subscript or superscript to a string and have it be treated as a string so it can be printed in TextFields, etc. I word it like that because I know about AttributedString, but it doesn't seem like that can be used interchangeably with regular text strings.
|
# ? Jun 24, 2011 20:39 |
|
Hidden Under a Hat posted:I feel like this should be something simple but I haven't been able to find a solution after quite a bit of googling... is there a way to add a subscript or superscript to a string and have it be treated as a string so it can be printed in TextFields, etc. I word it like that because I know about AttributedString, but it doesn't seem like that can be used interchangeably with regular text strings. If you use a character set (if such a character set exists) that can encode any character as a separate character that looks like a super/subscripted version. Otherwise no, a String does not natively support metadata.
|
# ? Jun 24, 2011 20:51 |
|
Hidden Under a Hat posted:I feel like this should be something simple but I haven't been able to find a solution after quite a bit of googling... is there a way to add a subscript or superscript to a string and have it be treated as a string so it can be printed in TextFields, etc. I word it like that because I know about AttributedString, but it doesn't seem like that can be used interchangeably with regular text strings. Unicode has a few pre-defined superscripts and subscripts, but not support for arbitrary strings in super/subscripts. See wikipedia for details. That said, some form of markup (or AttributedString) may be preferable. I've never done rich text display, so I'm not sure what the go-to solution is, or even what Swing elements display formatted text.
|
# ? Jun 24, 2011 21:37 |
|
Having some trouble launching an external process. This is trying to launch an external compiler for some files I've generated earlier. It's supposed to be a really quick hack job that only I will use, so don't fret too much about hardcoded paths. (Also please ignore some wonky naming conventions.) code:
code:
I'm running Win 7, and thought this might have something to do with permissions and stuff? Not sure how I can launch a jar with admin rights... Anyone got any tips on how to debug this? It's not too big of a deal since it works fine using Eclipse, but just doubleclicking a jar instead would be so much easier. asasfgasgf Edit: Literally five minutes later and turns out just using Runtime.getRuntime().exec(...); works just fine... I remember I had some very good reason for using ProcessBuilder before, but now I have no idea why. czg fucked around with this message at 00:08 on Jun 25, 2011 |
# ? Jun 25, 2011 00:00 |
|
czg posted:asasfgasgf Edit: Literally five minutes later and turns out just using Runtime.getRuntime().exec(...); works just fine... I remember I had some very good reason for using ProcessBuilder before, but now I have no idea why. ProcessBuilder's directory setting is just for setting the working directory, not setting the search path for the executable. My guess is that ProcessBuilder is doing something different in the forking process like searching for the executable before changing to the new working directory, so unless the location of your .exe is on the search path before-hand, or you are running the JAR from the same location as the .exe, it won't find the executable.
|
# ? Jun 25, 2011 05:43 |
|
question: is this not awesome http://www.youtube.com/watch?v=2a4RNw8A5L8&cc_load_policy=1
|
# ? Jun 25, 2011 06:43 |
|
Aleksei Vasiliev posted:question: is this not awesome
|
# ? Jun 25, 2011 12:39 |
|
Has anybody encountered problems with JAXB between Windows and Linux? We have been using JAXB to read in a 3rd part XML file into java object representations (autogenerated from the schema by xjc). On Windows this seems to work perfectly. All data is present and accounted for in their appropriate objects. On Linux data is missing, but no errors are emitted using a ValidationEventHandler, and the JAXB content indicated it knows about the classes (using .toString). At a loss as to what the problem is.
|
# ? Jun 25, 2011 20:23 |
|
Any chance you are using an open-source non-Oracle JVM? Some Linux distros such as Debian use these by default and I have noticed some subtle differences.
|
# ? Jun 26, 2011 02:30 |
|
Paolomania posted:Any chance you are using an open-source non-Oracle JVM? Some Linux distros such as Debian use these by default and I have noticed some subtle differences. Especially with the built in XML libraries. I honestly think that in Sun's quest to make this really abstract, open framework they made a mishmash of poo poo that takes years to really understand its nuances.
|
# ? Jun 26, 2011 02:40 |
|
Paolomania posted:Any chance you are using an open-source non-Oracle JVM? Some Linux distros such as Debian use these by default and I have noticed some subtle differences. Good question, actually. I'll forward along the question to whoever setup the OS. But, on the other hand . . . things magically started working. I hate these types of problems. My first thought was that whoever did the build didn't update, but I did watch them update and deploy. And I watched the incorrect results. So, still at a loss and its equally concerning that it has started working properly.
|
# ? Jun 26, 2011 15:13 |
|
Can someone give me a hand on building a .jar file and including a folder with some non-java resources in Eclipse? I'm building an app with an embedded Derby database and some .ini files. I've added them to my package in eclipse like this: I can access these resources just fine in my code by using "res/filename.here", and I've added that folder as a source folder in Eclipse, but when I build the .jar it copies the contents of the res folder into the jar, but *not* in a folder called res, just in the root of the .jar file, so my references in the code don't work anymore. I can fix this by changing the code, but then the compiled .jar works, but it doesn't work when I launch the project from Eclipse. I presume I'm just doing something wrong in the build config, how do I make this work? edit: I'm lying. The .jar version doesn't work with or without the "res" in the paths to the files. What am I doing wrong? chippy fucked around with this message at 14:52 on Jun 27, 2011 |
# ? Jun 27, 2011 14:21 |
|
chippy posted:I can access these resources just fine in my code by using "res/filename.here", and I've added that folder as a source folder in Eclipse, but when I build the .jar it copies the contents of the res folder into the jar, but *not* in a folder called res, just in the root of the .jar file, so my references in the code don't work anymore. I can fix this by changing the code, but then the compiled .jar works, but it doesn't work when I launch the project from Eclipse. I presume I'm just doing something wrong in the build config, how do I make this work? Are you trying to load the resources just using File/FileInputStream/FileReader objects? That will work when the resources are in files on your file system but not when they're in jars, because those classes don't know anything about jar files. You need to use getResource or getResourceAsStream instead, which will work correctly in both cases.
|
# ? Jun 27, 2011 15:04 |
|
All working now, thanks for that. edit: Although for the record the files that are in "res" in Eclipse are still in the root of the .jar and not in a folder called "res", any way of rectifying this?
|
# ? Jun 27, 2011 16:08 |
|
chippy posted:All working now, thanks for that. The folder 'res' does not exist in your JAR file for the same reason that 'src' does not exist either, they are just eclipse source roots, so to speak. If you want a subfolder to appear in the JAR, create a folder in eclipse under 'res' or 'src' and put the required files there instead.
|
# ? Jun 27, 2011 20:27 |
|
Yeah, makes sense. Thanks. Ok, another (probably silly) question: Using getResourceAsStream now that means that the program works fine when running from the .jar, but not when launched fro from the Run button in Eclipse. Is this a common situation? Is there some way around it?
|
# ? Jun 27, 2011 22:46 |
|
Long story short: File* classes use the file system, getResource* uses the classpath. What probably needs to happen is your resource file needs to get copied to the output build directory (where the intermediate .class files are stored), because it is this location that is on the classpath when you run in Eclipse (rather than your source folder).
|
# ? Jun 28, 2011 01:08 |
|
In netbeans simply copying the res folder to the src folder will copy them to the build directory whenever you build the project. I think Eclipse works the same way, and you get the benefit of having your res folder be a folder in the jar.
|
# ? Jun 28, 2011 01:17 |
|
Or in Netbeans, you add the res folder as a source folder in the project properties, then you don't have to have it under source, but it still gets copied into the jar properly, and you can run from within the IDE.
|
# ? Jun 28, 2011 04:25 |
|
Sorry, I'm not sure I follow. To be specific, if I build the .jar and run that it works fine, but if I launch from Eclipse the second line of this gives me a NullPointerException:code:
edit: If anyone's interested the answer seems to have been to edit the run configuration add "res" to the classpath. It now works when launched from the IDE and from the .jar. For some reason, the contents of res aren't copied to the output directory (bin) when it's run, I'm getting the impression they should be? edit#2: But now this only works if I have a copy of the .jar in the directory 1 below "res", if it delete it I can no longer open my Derby database. This is a different problem. gently caress this, it makes no sense. I'm having a paddy now. I give up trying to undestand. it's working, that'll do. chippy fucked around with this message at 11:14 on Jun 28, 2011 |
# ? Jun 28, 2011 10:17 |
|
chippy posted:Sorry, I'm not sure I follow. To be specific, if I build the .jar and run that it works fine, but if I launch from Eclipse the second line of this gives me a NullPointerException:
|
# ? Jun 28, 2011 12:20 |
|
I get that. My question was how to set up my project properly so that the resource in the .jar *is* found, even when launching from the IDE instead of running the .jar itself. I've got it working now although I'm not 100% sure how.
|
# ? Jun 28, 2011 12:57 |
|
In eclipse you need to add the jar to your project's build path.
|
# ? Jun 28, 2011 14:13 |
|
Try getClass().getResourceAsStream("/fileName.ini"); so the class loader starts looking for the resource from the root.
|
# ? Jun 28, 2011 14:57 |
|
|
# ? Jun 12, 2024 11:55 |
|
chippy posted:For some reason, the contents of res aren't copied to the output directory (bin) when it's run, I'm getting the impression they should be? Eclipse should copy everything over (I just double checked on my machine). The default working directory of an Eclipse project is the workspace root, whereas the build output (and effectively the uncompressed contents of your JAR) goes to ${workspace_loc}/bin. To get your run configuration to use objects on the file system in the same way as they appear in a JAR you will have to set your working directory to the bin directory manually (which it sounds like you did).
|
# ? Jun 28, 2011 16:17 |