2017-11-07 17 views
-1

私は現在、プロジェクト、Qrcodeジェネレータintellij javaでVcardを使用して作業しています。エラー: "非静的メソッドtoString()は、静的コンテキストから参照できません"

エラー: "非静的メソッドtoString()は静的コンテキストから参照できません"。

誰でもこのエラーを解決するのに役立つことができますか? ありがとうございます。

マイコード:

class HtmlWriter {  
    private final PrintWriter out;  
    private final File dir;  
    private int iota=1; 
       public HtmlWriter(File dir) throws IOException { 
       this.dir = dir; 
       this.out = new PrintWriter(new File(dir,"out.html")); 

       InputStream x = HtmlWriter.class.getResourceAsStream("/badges.html");    
     System.out.print(IOUtils.toString(HtmlWriter.class.getResourceAsStream("/badges.html")));  
       } 
       public void add(String firstName, String lastName, String company, String email, String tel) throws IOException,  WriterException { 
       VCardBuilder vc = new VCardBuilder(); 
       vc.with("N",firstName+" "+lastName) 
         .with("ORG", company) 
         .with("TEL", tel) 
         .with("EMAIL", email); 
       System.out.println(vc.toString()); 

       vc.writeQRCode(new File(dir,String.format("qr%04d.png",iota))); 

       out.printf(
         "<div class='badge'>\n" + 
           " <img class='qrcode' src='qr%04d.png'>\n" + 
           " <div class='cblogo'></div>\n"+ 
           " <div class='firstName'>%s</div>\n" + 
           " <div class='lastName'>%s</div>\n" + 
           " <div class='company'>%s</div>\n" + 
           "</div>\n", iota, firstName, lastName, company 
      ); 
       iota++; } 
       public void close() { 
       out.println("</body></html>"); 
       out.close(); 
         } 
         } 

答えて

0

あなたはsun.misc.IOUtilsを輸入しているが、あなたはおそらくorg.apache.commons.io.IOUtilsを望んでいました。 ApacheのIOUtilsは、Mavenプロジェクトでそれを使用するにはthe toString() method you want.

を持って次の依存関係が含ま:

<!-- https://mvnrepository.com/artifact/commons-io/commons-io --> 
<dependency> 
    <groupId>commons-io</groupId> 
    <artifactId>commons-io</artifactId> 
    <version>2.4</version> 
</dependency> 

またはプロジェクトのホームページからjarファイルダウンロード:https://commons.apache.org/proper/commons-io/download_io.cgi

+0

org.apache.commons.ioのインポートを.IOUtilsが "シンボルを解決できません"エラーを表示しています –

+0

あなたのクラスパスに必要なライブラリがありますか? – 1615903

関連する問題