본인이이 클래스에서 만든 함수를 주 도구로 사용하려고하는데 충돌이 발생하고 "경고 : 루트 0에서 prefs 루트 노드 Software \ JavaSoft \ Prefs를 열거 나 만들 수 없습니다 . x80000002 윈도우 RegCreateKeyEx (...)는 "주요"java.lang.NullPointerException이 내가) grabar.touchFile을 (수행하려고 할 때마다 스레드에서 오류 코드 5. 예외를 반환; 여기 텍스트 파일을 만들 때 Java nullpointexception
내가 만든 클래스입니다 : http://pastebin.com/eNWrp07fpackage 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();
}
}
어디 NullPointerException이이야? 실제 오류 메시지 없이는 당신을 도울 수 없습니다. – Gian
여기서'main'은 어디에 있습니까? – Bill
'Grabar.txt' 파일이 존재하지 않는다면, 새로운 파일을 생성 할 것이고 이것은'NumberFormatException' @이 줄'int mapaTexto = Integer.parseInt (dato);를 던질 것입니다. – SudoRahul