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 に答える