Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Self Coded Program run errors

I'm having trouble running the programs I made on computers. It works fine on the computer I coded it on but when I transfer to a friend or a computer in my house i get the error " a java exception has occurred". The code run fine in debug and run in eclipse and on own computer.
Does your friend have Java installed?
(Aug 5, 2014 10:19 AM)MrOrang Wrote:  Does your friend have Java installed?

Yes, also all my computer have the latest version of java on them


So does anyone have a solution that might help me...?
Does it print a stack trace, and if so can you provide it? Or does it literally just say "a java exception has occurred"?
You might be getting an IO exception or something because you're accessing a file on your machine which isn't on your friends PC. Read over your project and pin-point the issue.

[Image: cWKoYK1.gif]
(Aug 6, 2014 04:53 AM)Pumpkins Wrote:  You might be getting an IO exception or something because you're accessing a file on your machine which isn't on your friends PC. Read over your project and pin-point the issue.

I re-read the program and I found no issue. The image is in the package so that might not be the problem. This is the program is use for staffs on my minecraft server to create a text doc to send to me when they report someone but nobody can get it to work.
This is my code:
Code
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

public class OhNoHeDidnt {

    private JFrame frmOhNoHe;
    private JTextField textField;
    private JLabel lblReason;
    private JLabel lblProof;
    private JTextField textField_1;
    private JTextField textField_2;
    private JButton btnNewButton;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    OhNoHeDidnt window = new OhNoHeDidnt();
                    window.frmOhNoHe.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public OhNoHeDidnt() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frmOhNoHe = new JFrame();
        frmOhNoHe.setResizable(false);
        frmOhNoHe.setIconImage(Toolkit.getDefaultToolkit().getImage(OhNoHeDidnt.class.getResource("/image/black-woman-attitude.png")));
        frmOhNoHe.setTitle("ONHD");
        frmOhNoHe.setBounds(100, 100, 227, 177);
        frmOhNoHe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frmOhNoHe.getContentPane().setLayout(null);

        JLabel lblUser = new JLabel("User:");
        lblUser.setBounds(12, 13, 38, 16);
        frmOhNoHe.getContentPane().add(lblUser);

        textField = new JTextField();
        textField.setBounds(73, 10, 116, 22);
        frmOhNoHe.getContentPane().add(textField);
        textField.setColumns(10);

        lblReason = new JLabel("Reason:");
        lblReason.setBounds(12, 42, 56, 16);
        frmOhNoHe.getContentPane().add(lblReason);

        lblProof = new JLabel("Proof:");
        lblProof.setBounds(12, 71, 56, 16);
        frmOhNoHe.getContentPane().add(lblProof);

        textField_1 = new JTextField();
        textField_1.setBounds(73, 39, 116, 22);
        frmOhNoHe.getContentPane().add(textField_1);
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        textField_2.setBounds(73, 68, 116, 22);
        frmOhNoHe.getContentPane().add(textField_2);
        textField_2.setColumns(10);

        btnNewButton = new JButton("Submit");
        btnNewButton.setBounds(73, 103, 116, 20);
        btnNewButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if(textField.getText().trim().equals("")) {
                    JOptionPane.showMessageDialog(null, "A Username is required before submission!", "Missing Username    ", JOptionPane.ERROR_MESSAGE);
                }else {
                    if (textField_1.getText().trim().equals("")) {
                        JOptionPane.showMessageDialog(null, "A Reason is required before submission!", "Missing Reason    ", JOptionPane.ERROR_MESSAGE);
                    } else {
                        if(textField_2.getText().trim().equals("")) {
                        JOptionPane.showMessageDialog(null, "Proof is required before submission!", "Missing Proof    ", JOptionPane.ERROR_MESSAGE);
                        }else {
                        String user = textField.getText();
                        String reason = textField_1.getText();
                        String proof = textField_2.getText();

                        try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Oh No " + user + " Didn't.txt", false)))) {
                        out.print("======Start======");
                        out.println("");
                        out.print("User:");
                        out.print(user);
                        out.println("");
                        out.print("Reason:");
                        out.print(reason);
                        out.println("");
                        out.print("Proof:");
                        out.print(proof);
                        out.println("");
                        out.print("======End======");
                        } catch (IOException e1) {
                        e1.printStackTrace();
                        }
                        }
                    }
                }

            }
        });
        frmOhNoHe.getContentPane().add(btnNewButton);
    }
}

If you can find the error please help me...
Can you post a stack trace of the error log please?
(Aug 6, 2014 08:50 AM)RuffledUp Wrote:  Can you post a stack trace of the error log please?

The thing is there isn't a stack trace of the error. That's why I'm so confused.


(Aug 5, 2014 07:41 PM)Deal™ Wrote:  Does it print a stack trace, and if so can you provide it? Or does it literally just say "a java exception has occurred"?
it just flat out say "a java exception has occurred"
Have you tried getting the class resource as a stream?

[Image: cWKoYK1.gif]
(Aug 6, 2014 10:24 AM)Pumpkins Wrote:  Have you tried getting the class resource as a stream?

Can you explain how I might go at doing that?
If you are feeling lazy just wrap the questionable parts in a try block and print a stack trace. This will let you quickly pinpoint your issue. At a glance I would guess that the image is not being found in the package and you only tested in your IDE (where the file reference is slightly different). That may not be the case, but that would be my first guess.
(Aug 6, 2014 08:52 AM)YellowMilk Wrote:  The thing is there isn't a stack trace of the error. That's why I'm so confused.

Of course there is 😶 I dont mean just the console error. Again POST IT HERE as there is more information provided other than "a java exception has occurred". Stop being lazy

Is the error happening at compile or runtime?
(Aug 6, 2014 10:57 AM)RuffledUp Wrote:  Of course there is 😶 I dont mean just the console error. Again POST IT HERE as there is more information provided other than "a java exception has occurred". Stop being lazy

Is the error happening at compile or runtime?

http://prntscr.com/4a6umh: ran in eclipse with console and debug
http://prntscr.com/4a6v9w: ran on computer with no eclipse
http://prntscr.com/4a6w6j: ran on laptop

no error except "a java exception has occurred" on my laptop and other computers. And I'm not being lazy thank you very much. I'm trying to provide as much information as I can.
By the looks of it, it isn't an exception in the program but a problem is happening with the running of it. What JDK are you using to compile it with and what JRE are you running on your laptop. Also are you able to use the command line to launch the jar?
(Aug 6, 2014 11:22 AM)Ben121 Wrote:  By the looks of it, it isn't an exception in the program but a problem is happening with the running of it. What JDK are you using to compile it with and what JRE are you running on your laptop. Also are you able to use the command line to launch the jar?

Im compiling on jdk1.8.0_05 and my jre is 1.8 update 11 on my laptop. My laptop was updated yesterday and before I posted this question :/

Edit: I'll just redo the programs in C++ and see if that's better. Thanks everyone for trying to help.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by VoxiDec 1, 2018 12:20 AM 4 229 Dec 1, 2018 12:20 AM
Last Post: Europa
[.NET] by qbOFFICIALOct 18, 2014 12:43 PM 10 426 Oct 18, 2014 12:43 PM
Last Post: Nervo
[.NET] by sτιxιᴏOct 17, 2014 12:27 PM 17 654 Oct 17, 2014 12:27 PM
Last Post: IAmNotHere