Edit, resolved:
Resolution:
Step 1: Ensured seek methods went to the correct locations and written with the correct byte length. Fixed several seek misdirections.
Step 2: Updated java and jgrasp to latest versions. Fixed java crash but began receiving major-minor mismatch error.
Step 3: Went to the jgrasp control shell, opened start-up settings and selected the upgraded jre
Error Resolved
------------------------------------------------------------------------------------------
I'm writing a program to read and write a custom object (patient) to a random access file. At the moment though I'm just writing the individual components(two strings, 3 integers, and a double) to the file rather then the object itself. It worked fine for a bit and everything still compiles but then I started getting java.exe crash messages after I implemented the writePatientWeight. I've tried commenting out the new methods but it still crashes.
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);
}
}
The randomAccessMethods class:
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
以上就是Why would accessing a random access file be crashing the Java platform?的详细内容,更多请关注web前端其它相关文章!