0
method init in class Preferences cannot be applied to given types;
required: String
found: no arguments
reason: actual and formal argument lists differ in length

Preferences.init();在 NetBeans 中标记为红色

不知道是什么问题?

运行时出现以下错误:

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: processing.app.Preferences.init
    at arduinojava.ArduinoJava.main(ArduinoJava.java:34)
Java Result: 1

这是代码:

/*
* This class will get the input from arduino board and output
* the data to the scanner
* Code adopted from Silveira Neto
*/

package arduinojava;

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;

/**
*
* @author kinley tshering
*/
public class ArduinoJava {

static InputStream input;
static OutputStream output;
static CommPortIdentifier portId;
static SerialPort port;

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
  //code application logic here

     Preferences.init();
     System.out.println("Using port: " + Preferences.get("serial.port"));
    try {
            portId = CommPortIdentifier.getPortIdentifier(
                   Preferences.get("serial.port"));

          //port = (SerialPort)portId.open("serial talk", 4000);
          port = (SerialPort)portId.open("", 4500);
          input = port.getInputStream();
          output = port.getOutputStream();
           port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
                  SerialPort.DATABITS_8,
                  SerialPort.STOPBITS_1,
                  SerialPort.PARITY_NONE);

          while(true){
                      while(input.available() > 0) {
                                   System.out.print((char)(input.read()));
                       }
           }
  }
  catch(gnu.io.NoSuchPortException nsp)  {
       System.err.println("ERROR: " + nsp.getMessage());
   }
  catch(gnu.io.UnsupportedCommOperationException usp)  {
       System.err.println("ERROR: " + usp.getMessage());
   }
   catch(gnu.io.PortInUseException pie)  {
       System.err.println("ERROR: Port " + port + " is already in use\nCLose the port and restart.");
   }
   catch(java.io.IOException ioe) {
       System.err.println("IO ERROR: " + ioe.getMessage() );
   }
   catch(Exception exe) {
       System.err.println("ERROR: Unexpected error occured \n" + exe.getMessage() );
    }
}

}
4

2 回答 2

0
method init in class Preferences cannot be applied to given types;
required: String
found: no arguments

看来您在类中没有任何方法 init()没有参数Preferences

您需要调用以下内容:

Preferences.init("yourString");

注意:我们不知道调用方法yourString时应该是什么。init()

于 2012-11-29T22:34:19.197 回答
0

类 Preferences 中的方法 init 不能应用于给定类型;必需:找到字符串:无参数

错误说明了一切,您的 init() 方法需要一个 String 参数,而您没有传递任何参数。

这个 Preferences.init();

应该

 Preferences.init("pass a string argument here");
于 2012-11-29T22:34:33.953 回答