2013-05-07 2 views
0

본인이이 클래스에서 만든 함수를 주 도구로 사용하려고하는데 충돌이 발생하고 "경고 : 루트 0에서 prefs 루트 노드 Software \ JavaSoft \ Prefs를 열거 나 만들 수 없습니다 . x80000002 윈도우 RegCreateKeyEx (...)는 "주요"java.lang.NullPointerException이 내가) grabar.touchFile을 (수행하려고 할 때마다 스레드에서 오류 코드 5. 예외를 반환; 여기 텍스트 파일을 만들 때 Java nullpointexception

내가 만든 클래스입니다 : http://pastebin.com/eNWrp07f

package com.brackeen.javagamebook.grabar; 

import java.io.*; 

public class Grabar{ 
    private int mapaTexto; 
    private String nombreArchivo = "Grabar.txt"; 

    public void touchFile() throws IOException{ 
     File f = new File(nombreArchivo); 
     if (!f.isFile()) 
      f.createNewFile(); 
    } 

    public int readFile() throws IOException{ 
     try{ 
      touchFile(); 
     } catch(IOException ex){ 
      ex.printStackTrace(); 
     } 

     BufferedReader fileIn = new BufferedReader(new FileReader(nombreArchivo)); 
     String dato = fileIn.readLine(); 
     int mapaTexto = Integer.parseInt(dato); 
     fileIn.close(); 
     return mapaTexto; 
    } 

    public void writeFile(int n) throws IOException{ 
     try{ 
      touchFile(); 
     } catch(IOException ex){ 
      ex.printStackTrace(); 
     } 
     PrintWriter fileOut = new PrintWriter(new FileWriter(nombreArchivo)); 
     fileOut.println(n); 
     fileOut.close(); 
    } 

} 
+0

어디 NullPointerException이이야? 실제 오류 메시지 없이는 당신을 도울 수 없습니다. – Gian

+0

여기서'main'은 어디에 있습니까? – Bill

+0

'Grabar.txt' 파일이 존재하지 않는다면, 새로운 파일을 생성 할 것이고 이것은'NumberFormatException' @이 줄'int mapaTexto = Integer.parseInt (dato);를 던질 것입니다. – SudoRahul

답변

3

페스트병 덤프를 보면 문제가와 다릅니다. 10 클래스이지만, 귀하의 GameManager 클래스의 init() 기능을 사용하십시오. Grabar 인스턴스에서 touchFile()으로 전화를 걸려고했지만 아직 new 연산자로 인스턴스를 만들지 않았습니다.

init() 방법에 touchFile() 방법 전에 곳이 줄을 추가

grabar = new Grabar(); 
+0

와우, 대단히 고마워! 나는 그것이 어리석은 무엇인가 믿을 수 없다! – acrogenesis

관련 문제