Java编译错误:忽略新实例

Java编译错误:忽略新实例,java,Java,这是我使用itext创建pdf文档的java代码 package com.cdac.pdfparser; import java.io.FileOutputStream; import java.io.IOException; import java.util.*; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Paragraph; impo

这是我使用itext创建pdf文档的java代码

package com.cdac.pdfparser;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class PDFCreate {
    public static String RESULT = "results/part1/chapter01/";
    public static void main(String[] args)
    throws DocumentException, IOException {
        Scanner sc = new Scanner(System.in);
        String fileName = sc.nextLine();
        RESULT = RESULT + fileName;
        new PDFCreate.createPdf(RESULT);
    }
    public void createPdf(String filename)
    throws DocumentException, IOException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World!"));
        // step 5
        document.close();
    }
}
但我得到了一个编译错误:新实例被忽略

请帮帮我

    new PDFCreate.createPdf(RESULT);
          -------^
这不是创建
对象的正确方法

应该是

 new PDFCreate().createPdf(RESULT);
你忘了写
()

这不是创建
对象的正确方法

应该是

 new PDFCreate().createPdf(RESULT);

你忘了写
()

i使用new PDFCreate().createPdf(结果)更改新的PDFCreate.createPdf(结果)

newPDFCreate.createPdf(RESULT)不是在java中创建对象的正确方法

希望它能起作用

 package com.cdac.pdfparser;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;




  public class PDFCreate {
    public static String RESULT = "results/part1/chapter01/";
    public static void main(String[] args)
    throws DocumentException, IOException {
     Scanner sc = new Scanner(System.in);
     String fileName = sc.nextLine();
     RESULT = RESULT + fileName;
     new PDFCreate().createPdf(RESULT);
    }
     public void createPdf(String filename)
    throws DocumentException, IOException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World!"));
        // step 5
       document.close();

} }

我用new PDFCreate().createPdf(结果)更改new PDFCreate.createPdf(结果)

newPDFCreate.createPdf(RESULT)不是在java中创建对象的正确方法

希望它能起作用

 package com.cdac.pdfparser;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;




  public class PDFCreate {
    public static String RESULT = "results/part1/chapter01/";
    public static void main(String[] args)
    throws DocumentException, IOException {
     Scanner sc = new Scanner(System.in);
     String fileName = sc.nextLine();
     RESULT = RESULT + fileName;
     new PDFCreate().createPdf(RESULT);
    }
     public void createPdf(String filename)
    throws DocumentException, IOException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World!"));
        // step 5
       document.close();

} }

我还看到您将RESULT的值重新分配为
RESULT=RESULT+fileName。字符串是不可变的,这不是一个好的做法。字符串是不可变的,这不是一个好的做法。