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
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
解决方案 »
- 如何使用struts2的<s:optiontransferselect>标签传递一组对象值?
- spring懒加载
- j2EE技术学习
- Java 结果集遍历时空指针错误?救救我吧!!!
- tomcat编译jsp是错误,帮忙看看,谢谢。
- 请教struts下使用javascript做级联菜单的问题(急问)
- hibernate怎么操作oracle10g中的BLOB字段啊?
- 急啊!!!!数据层中无法实例化WebServices中的Bean对象吗????????
- 请问这个错误是什么原因引起的
- Application Server、Web Server、中间件、EJB容器的概念与区别!
- j2ee
- 请教一个简单的js代码调试问题
at Page.main(Page.java:22)至少指出来 22 行在哪吧?
System.out.println(arr1[1][1]);
有问题,arr1[][] 测试 arr1=null.所以报那个错误。