Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zewle
Aug 12, 2005
Delaware Defense Force Janitor
Do I need a method or something for the array?

Adbot
ADBOT LOVES YOU

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
If it's private, you do, if it's public you don't.

Zewle
Aug 12, 2005
Delaware Defense Force Janitor
Ah. Thanks. Accidentally got stuck putting it inside the constructor.

Zewle
Aug 12, 2005
Delaware Defense Force Janitor
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

Blacknose
Jul 28, 2006

Meet frustration face to face
A point of view creates more waves
So lose some sleep and say you tried
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?

Hidden Under a Hat
May 21, 2003

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?

chippy
Aug 16, 2006

OK I DON'T GET IT

Blacknose posted:

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?

Don't you need to escape the single quotes with a backslash?

baquerd
Jul 2, 2007

by FactsAreUseless

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.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
It looks like it's just not getting any matches. Try a .contains("`") to see if the character is being detected properly.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Zewle posted:

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.

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.

Zewle
Aug 12, 2005
Delaware Defense Force Janitor

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.

baquerd
Jul 2, 2007

by FactsAreUseless

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:
for (Student currStudent : studentArray) {
  System.out.println(currStudent.getName());
}

Blacknose
Jul 28, 2006

Meet frustration face to face
A point of view creates more waves
So lose some sleep and say you tried

Blacknose posted:

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?

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.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

baquerd posted:

Something like this:

code:
for (Student currStudent : studentArray) {
  System.out.println(currStudent.getName());
}

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.

Hidden Under a Hat
May 21, 2003
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.

baquerd
Jul 2, 2007

by FactsAreUseless

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.

Cubiks
Aug 31, 2005
I wish I had something witty to put here...

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.

czg
Dec 17, 2005
hi
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:
ProcessBuilder xwc_static_builder = new ProcessBuilder();
xwc_static_builder.directory(new File("D:\\Dev\\OgierLatest\\System\\Win32_x86_Release\\"));
						
List<String> XWC_args = new ArrayList<String>();
XWC_args.add("XWC_Static.exe"); //.EXE name
XWC_args.addAll(xtxPathList); //A list of file arguments 
xwc_static_builder.command(XWC_args);

try {
	Process XWC_Static = xwc_static_builder.start();
	XWC_Static.waitFor();
	System.out.println("OK I'm done.");
} catch (Exception ex) {
	handleException(ex, "Failed to start XWC");
	return;
}
Now, from within Eclipse this works perfectly, however when I've exported it to a .jar and run it from windows explorer, it throws this on the builder.start() line:
code:
java.io.IOException: Cannot run program "XWC_Static.exe"
	(in directory "D:\Dev\OgierLatest\System\Win32_x86_Release"): CreateProcess error=2, The system cannot find the file specified
	at java.lang.ProcessBuilder.start(Unknown Source)
	at cg.quake.WadExport.exportTexturesAndSurfaces(WadExport.java:161)
	at cg.quake.WadExport.main(WadExport.java:64)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	... 3 more
Now obviously the file in question exists, and I'm fairly certain this is not a problem with working directories as you can see it is looking in the right place.
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

Paolomania
Apr 26, 2006

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.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
question: is this not awesome

http://www.youtube.com/watch?v=2a4RNw8A5L8&cc_load_policy=1

zootm
Aug 8, 2006

We used to be better friends.

Aleksei Vasiliev posted:

question: is this not awesome

http://www.youtube.com/watch?v=2a4RNw8A5L8&cc_load_policy=1
Was watching that earlier. It does manage to somehow transcend "cringey geek humour" using production values. Bravo.

Luminous
May 19, 2004

Girls
Games
Gains
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.

Paolomania
Apr 26, 2006

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.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

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.

Luminous
May 19, 2004

Girls
Games
Gains

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.

chippy
Aug 16, 2006

OK I DON'T GET IT
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? :smith:

chippy fucked around with this message at 14:52 on Jun 27, 2011

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

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.

chippy
Aug 16, 2006

OK I DON'T GET IT
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?

ivantod
Mar 27, 2010

Mahalo, fuckers.

chippy posted:

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?

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.

chippy
Aug 16, 2006

OK I DON'T GET IT
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?

Paolomania
Apr 26, 2006

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).

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
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.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
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.

chippy
Aug 16, 2006

OK I DON'T GET IT
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:
InputStream iniFileIn = getClass().getResourceAsStream(iniFileName);
BufferedReader fileIn = new BufferedReader(new InputStreamReader(iniFileIn));
I've added the res folder as a source folder in Eclipse.

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

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

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:

code:
InputStream iniFileIn = getClass().getResourceAsStream(iniFileName);
BufferedReader fileIn = new BufferedReader(new InputStreamReader(iniFileIn));
getResourceAsStream returns null if the named resource wasn't found.

chippy
Aug 16, 2006

OK I DON'T GET IT
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.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
In eclipse you need to add the jar to your project's build path.

Max Facetime
Apr 18, 2009

Try

getClass().getResourceAsStream("/fileName.ini");

so the class loader starts looking for the resource from the root.

Adbot
ADBOT LOVES YOU

Paolomania
Apr 26, 2006

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).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply