0
public class AplotPdfPrintLocal extends ApplicationWindow {
private String userSelectedFile;

public AplotPdfPrintLocal(String pdfFilePath) {
   super(null);
   this.userSelectedFile = pdfFilePath;
}

public void run() {
   setBlockOnOpen(true);
   open();
   Display.getCurrent().dispose();
}

etc........

クラスBから上記のクラスを実行したい

メソッドはクラス B - 以下

public void startPDFPrint() throws Exception {
      AplotPdfPrintLocal pdfPrint = new AplotPdfPrintLocal(getPDFFileName()).run();
}

run の戻り値の型を void から plotPdfPrintLocal に変更する必要があるというエラーが表示されます

クラスを間違って呼び出すつもりですか?

4

1 に答える 1

4

次のように変更します。

public void startPDFPrint() throws Exception {
      AplotPdfPrintLocal pdfPrint = new AplotPdfPrintLocal(getPDFFileName());
      pdfPrint.run();
}

また

public void startPDFPrint() throws Exception {
      new AplotPdfPrintLocal(getPDFFileName()).run();
}

コンパイラが言っているのは、 run メソッドの結果 ( void ) を式の左側のメンバーであるAplotPdfPrintLocal pdfPrint変数に代入しようとしているということです。

そのため、runがvoidを「返す」ため、予想されるAplotPdfPrintLocal型 (左側で宣言されている) と実際の戻り値の型: voidの間に不一致というエラーが発生します。

于 2012-11-12T22:50:26.363 に答える