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
Fruit Smoothies
Mar 28, 2004

The bat with a ZING

dvinnen posted:

Kinda sorta. It's in between a scripting language and a full compile I guess.

Java is compile down to byte code. This does make decompiling easier but not 100% accurate. Comments are striped of course and I'm sure other optimizations are performed on the code. Variable names are changed to become more machine friendly. The decompiler makes due with these by assigning the variables the same name as the class name.

Right, well at the moment, I can't even get the imported, unaltered JAR file to "run as applet" because it says the selection doesn't contain one.

Any ideas?

Adbot
ADBOT LOVES YOU

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Actually, I might be wrong about the decompiler, looked at some of my code compiled code with DJ and it mostly matches the java code. So I dunno, when I've used it before it's always given me code that looks like "Object object1 = new Object()"

As for the applet, it runs in a browser right? What does the HTML code call? Should look something like this:

code:
<APPLET ARCHIVE= "demo.jar,
	CODE="demo.applet.Applet1" width=640 height=260
	ALT="You should see an applet, not this text.">
</APPLET>
What ever CODE is pointing to is the main class, IIRC.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
code:
<applet width="765" height="450" name="cs" archive="Java/file.jar" codebase="http://server.com/Java/" code="com.appname">
<param value="params/param.prm?code=xxxxx" name="paramPath"/>
This application requires Java support
</applet>
Although I haven't yet managed to get this working on my server.

How do I then configue eclipse with the param?

Sorry, I have tried to google these questions. It's difficult because I'm not entirely sure what I'm trying to do here.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Decompile all the code, add it to an Eclipse project, right click on 'com.appname' and choose 'run as applet'.

Not sure how much help it'll be without the original source code.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

dvinnen posted:

Decompile all the code, add it to an Eclipse project, right click on 'com.appname' and choose 'run as applet'.

Not sure how much help it'll be without the original source code.

I now get "applet not initialised"

EDIT: That seems to be OK now.

\/\/\/\/\/

Yeah, the class path is actually /folder/com.app

Fruit Smoothies fucked around with this message at 19:46 on Nov 12, 2008

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Fruit Smoothies posted:

I now get "applet not initialised"

ugh, lots of things cause that. Usually has to do with the classpath isn't matching up. Also you try passing the parameter you have to it. Right click on the class and choose run configurations. There is a tab for parameters.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

dvinnen posted:

ugh, lots of things cause that. Usually has to do with the classpath isn't matching up. Also you try passing the parameter you have to it. Right click on the class and choose run configurations. There is a tab for parameters.

Yeah I've fiddled around. I'm now super confused, because it seems the applet it trying to create a HTML file. I have no idea if this is true for all applets, or just this one.

Either way, I have got no idea where Java would create it if it was being run. Hell I'm not even sure if the applet compiled properly:

code:
I/O exception while reading: C:\workspace\SourceTest\bin\comapp.class1226516468170.html
(The system cannot find the file specified)

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Eclipse makes that file when it runs an Applet automatically. Generates the HTML to embed in a page or something, I always ignore it. No idea why it can't be read though. Is it even getting written? Permissions problem?

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

dvinnen posted:

Eclipse makes that file when it runs an Applet automatically. Generates the HTML to embed in a page or something, I always ignore it. No idea why it can't be read though. Is it even getting written? Permissions problem?

Nothing to do with permissions. Users, Administrators and System have full access, and it's not read only either. Hell, eclipse has already generated "java.applet.policy" file in there.

Does the attempt to read this file imply compiler success?

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
Right, I'm getting literally nowhere with this thing. I copied the algorithm I wanted from the class file, trouble is, the decompiling process messed up some of the constant strings it uses, so I have no idea how on earth I can check it with java.

Essentially, I want to rewrite the whole procedure in pascal however this is looking impossible without the source.

I looked in using JNI to port the functions class' to delphi, but this looks like a lost cause. I am in no way competent enough in C++ to try and use the JNI.

My next thought was if .class files can be compiled down to DLLs completely? It would make a lot of sense for Sun to make this possible, since the language is limited mainly by the need of a platform.

dancavallaro
Sep 10, 2006
My title sucks
When I'm done with a project in Eclipse, is there an easy/automated way to deploy the project as an executable JAR file? Or I guess I'm just asking, what's the best way to deploy an Eclipse project as an executable application?

Mill Town
Apr 17, 2006

dancavallaro posted:

When I'm done with a project in Eclipse, is there an easy/automated way to deploy the project as an executable JAR file? Or I guess I'm just asking, what's the best way to deploy an Eclipse project as an executable application?

It should already be compiled to a JAR which you can run with java -jar <filename>

lamentable dustman
Apr 13, 2007

🏆🏆🏆

dancavallaro posted:

When I'm done with a project in Eclipse, is there an easy/automated way to deploy the project as an executable JAR file? Or I guess I'm just asking, what's the best way to deploy an Eclipse project as an executable application?

Right click on the project, choose export, expand Java. You'll have the option for JAR and executable JAR.

dancavallaro
Sep 10, 2006
My title sucks

dvinnen posted:

Right click on the project, choose export, expand Java. You'll have the option for JAR and executable JAR.

This worked perfectly, thanks. Now my next question is how to access an image file from within the JAR. This is the code I use to load the image:

code:
BufferedImage img = ImageIO.read(new File(getClass().getResource("image.bmp").toURI()));
This works fine when I run it from Eclipse, but when I run the executable JAR, the images don't show up. It doesn't even throw an exception - there's just no images. There are no directories within the JAR - everything is in the top level. Any ideas what the problem is?

edit: I've narrowed the problem down to that line, specifically. No exception is thrown, the program just silently breaks. If I throw in some print statements directly before and directly after that line, the one before is printed, but the one after is not. The strange thing is, the program continues to work normally. It doesn't throw an exception, but somehow exits the try {}catch{} block... what the gently caress is going on here?

dancavallaro fucked around with this message at 17:40 on Nov 13, 2008

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Google says to use a stream instead of File.

code:
BufferedImage img = ImageIO.read(getClass().getResourceAsStream("image.bmp"));
or something, didn't try it. Google "java read files inside jar" for some examples.

dancavallaro
Sep 10, 2006
My title sucks

dvinnen posted:

Google says to use a stream instead of File.

code:
BufferedImage img = ImageIO.read(getClass().getResourceAsStream("image.bmp"));
or something, didn't try it. Google "java read files inside jar" for some examples.

Yeah, I finally figured out that you can't create a File object from a JAR resource.. so I just got rid of the new File() and the .toURI() and it worked fine, because ImageIO.read() will take a URL to a resource.

zootm
Aug 8, 2006

We used to be better friends.
Yeah. The File class should really be called Path, and you can't use it to refer to things within JARs.

Boz0r
Sep 7, 2006
The Rocketship in action.
Our spiteful instructor has added some lame requirements for an assignment for creating a java UI with a ball that changes colour according to the different buttons pressed. He's said that we have to do it all in one class and we can't write similar code multiple times. We've made a for-loop that adds actionListeners to the buttons, but the compiler complains that it can't access "i" in the following segment:

code:

        private static final String[] buttonNames = { "Red", "Green", "Blue" };

        for (int i = 0; i < 3; i++) {
            buttons[i].addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    Icon planet = new ChangeIcon(150, 150, buttonNames[i]); //Here it complains
                    label.setIcon(planet);
                    label.repaint();
                }
            });
        }
"Cannot refer to a non-final variable i inside an inner class defined in a different method"

How do I fix this? I can't very well make "i" final.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Create another class, not an anonymous class, that receives an integer in it's constructor.
code:
public class blah{

    private static final String[] buttonNames = { "Red", "Green", "Blue" }; 

    public void Constructor(){
        for (int i = 0; i < 3; i++){
            buttons[i].addActionListener(new ButtonListener (i));
        }
    }
}

class ButtonListener extends ActionListener{
    private int i;
    public ButtonListener(int i){
        this i = i;
    }

    public void actionPerformed(ActionEvent event){ 
        Icon planet = new ChangeIcon(150, 150, blah.buttonNames[this.i]);
        label.setIcon(planet); 
        label.repaint(); 
    } 
Also you should change that array of buttonNames at the top to an enum.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Boz0r posted:

"Cannot refer to a non-final variable i inside an inner class defined in a different method"

How do I fix this? I can't very well make "i" final.

Under the hood, an anonymous class is just a normal class with some implicit final fields containing all the values of the variables it uses from the enclosing scope. That is, suppose I've got code like this:

code:
class Total {
  int total;
  Runnable getAdder(final int count) {
    return new Runnable() {
      public void run() {
        total += count;
      }
    };
  }
}
That compiles exactly to code structured like this:

code:
class Total {
  int total;
  Runnable getAdder(int count) {
    return new _Total_Runnable(this, count);
  }
  private static class _Total_Runnable implements Runnable {
    private _Total_Runnable(Total _Total_this, int count) {
      this._Total_this = _Total_this;
      this.count = count;
    }
    public void run() {
      _Total_this.total += count;
    }
    private final Total _Total_this;
    private final int count;
  }
}
We call this a "closure", and say that the anonymous class "closes on" the reference to the Total object and the value of the variable count. What it doesn't do is close on the local variable itself (although other languages do this), because that would have a lot of repercussions for the implementation; that's why you can't write any local variables from enclosing scopes, only read them. In order to make this clear, Java forces you to tag all the closed-upon local variables as final. But you can always close on the current value of a mutable variable by storing it to a new variable and closing on that, like so:

code:
for (int i = 0; i < 3; i++) {
  final int fi = i;
  buttons[i].addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
      Icon planet = new ChangeIcon(150, 150, buttonNames[fi]);
      label.setIcon(planet);
      label.repaint();
    }
  });
}
Alternatively, since the button names never change, you can just create a final variable to hold buttonNames[i].

Kerris
Jul 12, 2006
Don't you fucking dare compliment a woman's voice on the forums, you fucking creepy stalker.
NetBeans users might want to look into SQE (Software Quality Environment).

"SQE is an attempt at providing first class NetBeans integration for different Software Quality Tools as FindBugs, PMD, CheckStyle, Lint4j and Dependency Finder."

The very latest snapshot for NetBeans 6.5 can be found here.

Lord Purple
Mar 7, 2006

Remove your eyes...
I've been trying to send a large file using udp with multiple packets by splitting the file up but I have been having trouble. I tried implementing it as a FileStream and sending the bytes as packets one at a time but I have had a hard time splitting the file and having it remember where it was last. Is there any easier way to fragment the file into a specified chunk of data and then send it or are there any classes that handle this for you in udp?

1337JiveTurkey
Feb 17, 2005

Use TCP instead? Otherwise, use NIO with the ByteBuffer and make an OutputStream that appends anything sent to it to the ByteBuffer and force out a datagram every time the ByteBuffer won't take any more bytes.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
If you're trying to stream a large file over UDP, you are basically going to have to reimplement everything that TCP does for you. I suppose you could be a bastard and ignore flow-control, but seriously, this is a large undertaking.

sonic bed head
Dec 18, 2003

this is naturual, baby!
I know this is an IDE question, but I don't want to really make my own thread for it. Is there a recommended plugin for eclipse to have FTP mapped to a project just like subclipse does for SVN servers? I want something that would just allow em to "commit" without having to upload in an external program. Thanks.

zootm
Aug 8, 2006

We used to be better friends.
This does SFTP, not seeing anything that FTP though. Of course the reason for this is that these things are "Team" providers for source control, and FTP isn't a source control system.

A Curvy Goonette
Jul 3, 2007

"Anyone who enjoys MWO is a shitty player. You have to hate it in order to be pro like me."

I'm actually just very good at curb stomping randoms on a team. :ssh:
Generic newbie java question:

Is it possible to have a method return two values or variables without first putting them into an array and returning the array?

From what I've found, this is impossible in Java and a lot of people have complained to Sun about it, but the exercise I'm working on insists it can be done. I'd love to be proven wrong since it would make my life a lot easier.

Mill Town
Apr 17, 2006

A Curvy Goonette posted:

Generic newbie java question:

Is it possible to have a method return two values or variables without first putting them into an array and returning the array?

From what I've found, this is impossible in Java and a lot of people have complained to Sun about it, but the exercise I'm working on insists it can be done. I'd love to be proven wrong since it would make my life a lot easier.

The very definition of a functionmethod means you can't return two variables.

You can, however, create a class that contains only the two variables you want and return a member of that class.

shrughes
Oct 11, 2008

(call/cc call/cc)
Just return them in some object that contains two fields.

hexadecimal
Nov 23, 2008

by Fragmaster

A Curvy Goonette posted:

Generic newbie java question:

Is it possible to have a method return two values or variables without first putting them into an array and returning the array?

From what I've found, this is impossible in Java and a lot of people have complained to Sun about it, but the exercise I'm working on insists it can be done. I'd love to be proven wrong since it would make my life a lot easier.

in C++ i use std::pair a lot, and in Java I had to make my own quick class called Pair. So like 2 users above me said, just create a wrapper class for 2 values. You can make it generic and make hash and compareTo methods for it so you can use it almost anywhere in java.util.*

Blackout
Jun 29, 2005

I am a deathdealer.
Hey guys, I've got another question for you all. Hopefully it belongs here...

I'm building an RCP project in Eclipse 3.4 and I'm getting a java.lang.VerifyError.
I've got a class (Class A) which extends a parent (Class B). Class B is located in an external jar file that I import through my plugin.xml file on the Dependencies tab.

The problem is that when I try to instantiate this object anywhere in my project, I get this error:

code:
java.lang.VerifyError: (class: qc_studio/utilities/QCStudioTestRunner, 
method: <init> signature: (Ljava/lang/String;)V) Incompatible argument to function
The weird thing is that I only get this error when I try to create the object when I launch the RCP project as a whole. If I include the line

code:
QCStudioTestRunner q = new QCStudioTestRunner();


in the constructor for a view, that view won't be able to load properly. However, if I write a public static main method inside the view, put the line in there and run the individual class as a java app, I don't run into any errors.

I really don't understand why this is happening. If anyone has any insight it would be greatly appreciated! Thanks!

ndb
Aug 25, 2005

This is a tad bit on the web application side of things, but if I need to move this, let me know.

Using Struts, I have a JSP file that I'd like to display a message depending on the value of a variable.

For a hypothetical example:

Let's say the user inputs a value for x. Whenever x is 666 I want to to print "The devil's number is actually 616.", on the page, with the rest of the text, otherwise I don't want anything to show up.

Right now I have it going to System.out, which is helpful, but I want to put it right on the page.

Any suggestions, help?

crm
Oct 24, 2004

Clock Explosion posted:

This is a tad bit on the web application side of things, but if I need to move this, let me know.

Using Struts, I have a JSP file that I'd like to display a message depending on the value of a variable.

For a hypothetical example:

Let's say the user inputs a value for x. Whenever x is 666 I want to to print "The devil's number is actually 616.", on the page, with the rest of the text, otherwise I don't want anything to show up.

Right now I have it going to System.out, which is helpful, but I want to put it right on the page.

Any suggestions, help?

look into action/field message/errors

ndb
Aug 25, 2005

crm posted:

look into action/field message/errors

Does it matter that it's not associated with a bean?

Kennedy
Aug 1, 2006


hard to breathe?
nm

Kennedy fucked around with this message at 16:33 on Nov 29, 2008

JulianD
Dec 4, 2005
I'm writing a program that's supposed to test various characteristics of arrays. I've completed the program, and everything works appropriately; however, I'm getting an error that resets my interactions after the program finishes running that says, "java.lang.NoClassDefFoundError: com/sun/jdi/VMOutOfMemoryException". I've never seen an error like this before, and I'm not sure how to handle it (Googling the error didn't come up with anything that made sense to me). Is this just another exception that I need to throw in declaring my method main?

hexadecimal
Nov 23, 2008

by Fragmaster

JulianD posted:

I'm writing a program that's supposed to test various characteristics of arrays. I've completed the program, and everything works appropriately; however, I'm getting an error that resets my interactions after the program finishes running that says, "java.lang.NoClassDefFoundError: com/sun/jdi/VMOutOfMemoryException". I've never seen an error like this before, and I'm not sure how to handle it (Googling the error didn't come up with anything that made sense to me). Is this just another exception that I need to throw in declaring my method main?

Increase how much memory you give to your program. You are probably trying to allocate a new array after you used up all memory.

do something like java -Xmx1000m

Alternatively you can try and force garbage collector to free some memory at specific points if you know you don't need it anymore. To do this, you can set the references pointing to memory you don't need anymore to null.

JulianD
Dec 4, 2005

hexadecimal posted:

Increase how much memory you give to your program. You are probably trying to allocate a new array after you used up all memory.

do something like java -Xmx1000m

Alternatively you can try and force garbage collector to free some memory at specific points if you know you don't need it anymore. To do this, you can set the references pointing to memory you don't need anymore to null.

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:

code:
double freeMem;
Runtime r = Runtime.getRuntime();
freeMem = r.freeMemory();
System.out.println("free memory after creating array:  " + freeMem);
I only declared freeMem and r once; I inserted the last two lines before and after the last method of my program. In doing so, the amount of available memory before and after was 3768200.0 and 3359536.0, respectively. The program doesn't appear to be out of memory, so am I interpreting this incorrectly or is it something else causing the problem?

hexadecimal
Nov 23, 2008

by Fragmaster

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:

code:
double freeMem;
Runtime r = Runtime.getRuntime();
freeMem = r.freeMemory();
System.out.println("free memory after creating array:  " + freeMem);
I only declared freeMem and r once; I inserted the last two lines before and after the last method of my program. In doing so, the amount of available memory before and after was 3768200.0 and 3359536.0, respectively. The program doesn't appear to be out of memory, so am I interpreting this incorrectly or is it something else causing the problem?

I am not sure. Just try to use -Xmx and see if it helps. Also print stack trace of exception to System.err
just use printStackTrace() on exception after you catch it.

Adbot
ADBOT LOVES YOU

JulianD
Dec 4, 2005
I'm also having trouble giving the user a choice of bringing the input in from a file or inputting it themselves. Here's what I had written:

code:
String choice1, choice2, dataLoc;
int x, y;    
    
choice1 = JOptionPane.showInputDialog("Do you want to import the elements for array alpha from a file?"
                                           + "  If not, you will be able to enter the elements yourself.");
    
if (choice1 == "yes" || choice1 == "Yes")
{
  System.out.println("Please type the precise file name as a .dat location.");
  dataLoc = console.next();
  
  Scanner inFile = new Scanner(new FileReader(dataLoc));
  
  while (inFile.hasNext())
  {
    for (x = 0; x < 20; x++)
    {
      alpha[x] = inFile.nextInt();
    }
  }
}
else
{
  inputArray();
}
When the GUI window pops up and I input yes or Yes, it asks me to input the elements of the array myself, which I think indicates that the strings I'm putting into my GUI window aren't being stored in memory for choice1 to point to for the if...else statement. Even if I could resolve that problem, I'm not sure that I've set up the body of the if statement correctly to accept inputs from a file.

hexadecimal, I'm still in an intro Java class, so I've never used the commands that you're referring to, so I really don't understand what you're suggesting I do to handle the memory exception.

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