2017-11-07 7 views
-1

현재 Intellij java에서 Vcard를 사용하는 Project, Qrcode generator에서 작업하고 있습니다.오류 : "정적 컨텍스트에서 비 정적 메서드 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을 원했다. 아파치 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