简体   繁体   中英

Why do i get this error?

this is the snippet that produces an error saying :

')' expected
';' expected
not a statement
cannot find symbol
symbol : variable ActionEvent

The snippet :

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {
    JFileChooser chooseToAdd = new JFileChooser();
    int option = chooseToAdd.showOpenDialog(this);
    if( option == JFileChooser.APPROVE_OPTION ) {
        nameOfAudioFile = chooseToAdd.getSelectedFile().getAbsolutePath();
        //clonejTree1ValueChanged( TreeSelectionEvent evt );
        tester(java.awt.event.ActionEvent evt);
    }
}

private void tester(java.awt.event.ActionEvent evt) {
    System.out.println("tester");
}

Is there any syntax error ?

This method invocation is wrong:

tester(java.awt.event.ActionEvent evt);

That's trying to declare a parameter, but you need to be passing an argument. I suspect you want:

tester(evt);

It's important to understand the difference between a method declaration (which declares parameters with names and types) and a method invocation (which supplies values for those parameters).

As an aside, assuming you're quite new to Java I would recommend not starting off with Swing or any other kind of UI. I would suggest you start off writing some simple console apps that let you get to grips with the basic syntax of Java without having to worry about all the complexities introduced by user interfaces.

This line is wrong:

tester(java.awt.event.ActionEvent evt);

Here you should pass an object of the type ActionEvent.

So it should be something like this:

tester(evt);

Call

tester(evt); 

instead of

tester(java.awt.event.ActionEvent evt);

You shouldn't define the type there, it is already known. Method invocation syntax is not the same as method definition.

If you call a method, you don't have to provide the type of the parameter. So in line 6 of the snippet it only should be

tester(evt);

从中删除类型定义

tester(java.awt.event.ActionEvent evt);    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM