편집 : 해결 :랜덤 액세스 파일에 액세스하면 Java 플랫폼이 손상되는 이유는 무엇입니까?
1 단계 : 올바른 검색 방법이 올바른 바이트 길이로 기록되었는지 확인합니다. 몇몇 잘못된 방향 찾기를 수정했습니다.
2 단계 : java 및 jgrasp를 최신 버전으로 업데이트했습니다. Java 충돌이 수정되었지만 major-minor mismatch 오류가 발생하기 시작했습니다.
3 단계 :의 jgrasp 제어 쉘에 갔다 스타트 업 설정을 열고 업그레이드 된 JRE 오류
내가 읽고 사용자 지정 개체를 작성하는 프로그램을 쓰고 있어요 (환자를) 해결 선택 무작위 액세스 파일. 지금은 객체 자체보다는 파일에 개별 구성 요소 (두 개의 문자열, 3 개의 정수 및 이중)를 쓰고 있습니다. 그것은 조금 잘 작동하고 모든것은 여전히 컴파일하지만 writePatientWeight를 구현 한 후에 java.exe 충돌 메시지를 받기 시작했습니다. 새로운 방법을 주석 처리하려고했지만 여전히 충돌합니다.
import java.io.*;
public class randomTest extends randomAccessMethods{
public static void main (String args[])throws IOException{
RandomAccessFile test=createNewFile("test", "rw");
writePatientID(test, 1234567891);
writePatientFName(test, "Derrick");
writePatientLName(test, "Hollenbeck");
writePatientAge(test, 18);
writePatientRisk(test, 10);
writePatientWeight(test, 155);
test.seek(0);
int i=test.readInt();
System.out.println(i);
test.seek(40);
String fname=test.readUTF();
System.out.println(fname);
test.seek(57);
String lname=test.readUTF();
System.out.println(lname);
test.seek(81);
int age=test.readInt();
System.out.println(age);
test.seek(93);
int risk=test.readInt();
System.out.println(risk);
test.seek(101);
double weight=test.readDouble();
System.out.println(weight);
}
}
randomAccessMethods 클래스 :
import java.io.*;
public class randomAccessMethods extends CriticalPatientQueue{
public static RandomAccessFile createNewFile(String name, String readwrite) throws IOException{
if(readwrite!= "r"){//insures that there is a usable read/write variable, defaults to "rw" if there isn't
if(readwrite!= "w"){
if(readwrite!= "rw"){
readwrite="rw";
}
}
}
RandomAccessFile file=new RandomAccessFile(name+".dat", readwrite);
return file;
}
public static void writePatientID(RandomAccessFile file, int id)throws IOException{
file.seek(0);
file.writeInt(id);//writes the ID to the file, uses 40 bytes(id will always be length 10)
}
public static void writePatientFName(RandomAccessFile file, String fname)throws IOException{
file.seek(40);
file.writeUTF(fname);//writes the name to the file, uses 17 bytes(fname will always be length 15 + 2 for overhead)
for(int i=0; i<(17-fname.length()); i++){
file.writeUTF(" ");
}
}
public static void writePatientLName(RandomAccessFile file, String lname)throws IOException{
file.seek(57);
file.writeUTF(lname);//writes the name to the file, uses 24 bytes(fname will always be length 22 + 2 for overhead)
for(int i=0; i<(22-lname.length()); i++){
file.writeUTF(" ");
}
}
public static void writePatientAge(RandomAccessFile file, int age)throws IOException{
file.seek(81);
file.writeInt(age);//writes the age to the file, uses 12 bytes(age will always be length 3)
}
public static void writePatientRisk(RandomAccessFile file, int risk)throws IOException{
file.seek(93);
file.writeInt(risk);//writes the risk value to the file, uses 8 bytes(risk will always be length 2)
}
public static void writePatientWeight(RandomAccessFile file, double weight)throws IOException{
file.seek(101);
file.writeDouble(weight);//writes the weight to the file, uses 24 bytes(weight will always be length 3 for overhead)
}
}
충돌이 스택 추적과 함께 발생합니까? – Barend
"충돌"이란 무엇을 의미합니까? 어떤 오류 메시지가 나타 납니까? – cdeszaq
다음 메시지와 함께 java.exe 크래시가 발생합니다. java.exe에 문제가있어서 프로그램을 종료해야합니다. 불편을 끼쳐 드려 죄송합니다. – Gargoame