求大神给看一下程序!!!!!!
import java.io.*;import java.util.Scanner;
public class Page {
static String fileName1;
static String fileName2;
static int arr1[][];
static int arr2[];
public static void main(String args[]){
System.out.println(" /**********分页地址变换模拟**********/");
Scanner reader1=new Scanner(System.in);
System.out.print("请输入页表的文件名:");
fileName1=reader1.nextLine();
System.out.println("读入页表的情况是:");
fileDataToArrays(fileName1);
Scanner reader2=new Scanner(System.in);
System.out.print("请输入访问串的文件名:");
fileName2=reader2.nextLine();
System.out.print("读入的访问串:");
fileDataToArray(fileName2);
System.out.println("-------------------------");
System.out.print("地址变换结果是:");
System.out.println(arr1[1][1]);
pager();
}
public static void fileDataToArrays( String fileName){
FileReader inOne = null;
try {
inOne = new FileReader(fileName);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
BufferedReader inTwo=new BufferedReader(inOne);
String str = null;
try {
while((str=inTwo.readLine())!=null){
System.out.println(str);
}
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
str = inTwo.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int j=0,k=0;
while(str!=null){
String []strArr=str.split(" ");
for(int i=0;i<=7;i++){
while(strArr[k].equals(" ")){
k++;
arr1[j][i]=Integer.parseInt(strArr[k++].trim());
}
j++;
try {
str=inTwo.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void fileDataToArray( String fileName){
FileReader inOne = null;
try {
inOne = new FileReader(fileName);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedReader inTwo=new BufferedReader(inOne);
String str = null;
try {
while((str=inTwo.readLine())!=null){
System.out.println(str);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
str = inTwo.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int k=0;
while(str!=null){
String []strArr=str.split(" ");
for(int i=0;i<=6;i++){
while(strArr[k].equals(" ")){
k++;
arr2[i]=Integer.parseInt(strArr[k++].trim());
}
}
}
}
public static void pager(){
int i=0;
int j=0;
int a = 0;
int b=0;
for(i=0;i<=6;i++){
b=arr2[i]%1024;
a=arr2[i]/1024;
for(j=0;j<7;j++){
if(a==arr1[j][0]){
if(a>=0&&a<=3){
System.out.print(b+arr1[j][1]*1024+" ");
}
if(a>=4&&a<=7){
System.out.print("缺页 ");
}
}
else System.out.print("越界 ");
}
}
}
}
Exception in thread "main" java.lang.NullPointerException
at Page.main(Page.java:22)程序总是报错,哪里的问题?
两个txt 文件如下:
0 5 1
1 9 1
2 10 1
3 7 1
4 -1 0
5 -1 0
6 -1 0
7 -1 0 3296 2268 1366 1537 9879 6532 7769
--------------------编程问答-------------------- 自己顶一个先 --------------------编程问答-------------------- 求大神!!! --------------------编程问答-------------------- Exception in thread "main" java.lang.NullPointerException
at Page.main(Page.java:22)
至少指出来 22 行在哪吧? --------------------编程问答-------------------- pager();
就是这行。 --------------------编程问答--------------------
你肯定看错了,这是个函数调用,不会发生空指针错误。。。 --------------------编程问答-------------------- 我的函数里面使用了数组,应该是数组的问题 但是具体是哪里错误我不是很清楚 --------------------编程问答-------------------- 象是这句:
System.out.println(arr1[1][1]);
有问题,arr1[][] 测试 arr1=null.所以报那个错误。
补充:Java , Java EE