can anyone tell me why I'm getting the error Exception in thread "main" java.lang.NullPointerException at test_package.First_class.main(First_class.java:14) This is my code. it is designed to choose a random Parea and print it to the screen and then the Earea array in the same way. (please ignore the Areabase and the switch unless that is contributing to the error. Areabase is only there temporary)
package test_package;
import java.util.Scanner;
public class First_class {
private static final String[] Parea = null;
private static final String[] Earea = null;
public static void main(String[] args){
int Areabase = 1;
Scanner keyin = new Scanner(System.in);
switch (Areabase) {
case 1:
Parea[1] = "You enter what looks like it was once the ship cafateria but is now in ruin.";
Parea[2] = "You find yourself in a hallway, some of the lights are broken and the doors barely work.";
Parea[3] = "You enter an old storage room and almost slip into the huge hole that has opened up in the floor.";
Parea[4] = "You walk into the ships bathroom, the toilets are overflowing and the soap has a bite out of it.";
Parea[5] = "This seems to be an outdated controll deck, you wonder why it is here then you decide to move on.";
Parea[6] = "You emerge into the libary and almost trip over a stack of books. i lybrarian woould scream at this mess";
Parea[7] = "You find yourself in a room you dont reconise. there is glass all over the ground.";
Parea[8] = "You enter the main controll room. it seems that the entire front of the ship has colapsed.";
Parea[9] = "You walk into the ship's dorm. one room is littered with cat posters. Hang in there one says.";
Parea[10] = "This seems to have once been a black marketing room. you think you now understand the bounty.";
Parea[11] = "You emerge into a rapidly changing simulation room. it changes to a beach, a castle, YOUR SHIP?";
Parea[12] = "You move into the prisoner room. all the cells are open. people must have busted out.";
Parea[13] = "You trip and fall into the life support room. this room is badly dammage, badly badly dammages.";
Parea[14] = "You float into a random empty room. you emediatly know what it is. an anti gravity room.";
Parea[15] = "This room appears to be a half caved in engenerring room. maby you should leave befor those barrels explode.";
Earea[1] = "This room is on fire";
Earea[2] = "An explotion rocks the ship";
Earea[3] = "This room smells foul";
Earea[4] = "you wish you could take this room back to your ship";
Earea[5] = "THIS ROOM IS FILLED WITH ANIME";
int random = (int) Math.floor(Math.random() * (15 - 1) + 1);
int random2 = (int) Math.floor(Math.random() * (5 - 1) + 1);
System.out.println(Parea[random]);
System.out.println(Parea[random2]);
break;
default:
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire