Hi,

i try to handle a Neagtive number exception in my code.
i tried this but it shows "illegal start of type"
why please?

Here is my code:

public class JPanelTemporal extends javax.swing.JPanel {
public JPanelTemporal() {
        initComponents();
    }
 public void setDuration(int duration){
    this.jSpinnerDuration.setValue(duration);
    }
    public Time getTime(){

    Time time = new ElementTime((Integer)jSpinnerDuration.getValue(),
        (Integer)jSpinnerProbability.getValue(),
        (Integer)jSpinnerStart.getValue());
        return time;              
    }
    //
    Here i add this to Handle the error
    try{
    temp = JOptionPane.showInputDialog();
        ElementTime = Integer.parseInt(temp);
        if (ElementTime < 0) {
            throw new IllegalArgumentException();
        }
        outputMessage = "The duration time must be a positive number!";
        JOptionPane.showMessageDialog(null, outputMessage);
    }
    catch( InputMismatchException e)    
{
    JOptionPane.showMessageDialog();
    }//end catch

    catch( IllegalArgumentException e)
{
JOptionPane.showMessageDialog(null, outputMessage);

    }//end catch

Thank you

do you still get that error?
well, if your code is like:

//

Here I add ...

then that's bound to cause problems.

is the above your entire code? you're not closing your method/class. if you still get an error, can you post the correct (and complete) code, along with the correct error message? it'll make it easier to help you, since normally it should state where in the code the error occurs.

Sorry, the comments is just after //
And the error occurs at line 17.
THank you

If you carefully read stultuske reply, you should know that the symbol // is the starting comment. Then you have a new line on Here I add... which should immediately follow the symbol, not in another line (has a new line). Because of that, the Here i... is the illegal start of type statment. You do not have a class named Here, don't you? If you have a class named Here, the error will be right after the letter i.

PS: Actually after I looked at your code, your try-catch statement is outside a method??? That's not allowed.

Edited 4 Years Ago by Taywin

Yes thank you, the problem with // is just an error of copy/paste.
So i solved the problem in the properties of the gui in netbeans, now it's working thank you all...

This question has already been answered. Start a new discussion instead.