I was doing an assignment for a Computer Science course I'm taking and I tried to declare 3 String arrays in one line but it kept giving me this error message
java.lang.NullPointerException
I messed around with it a bit and I fixed the problem by changing
public static String[] offence,name,date = new String[8];
to
public static String[] offence,name = new String[8];
public static String[] date = new String[8];
Why does it only work when I do this?
PS, I'm new so go easy on me.
package pDatabaseApp;
import java.io.*;
public class PDatabaseMenu {
public static String[] offence,name = new String[8];
public static String[] date = new String[8];
public static void main(String[] args) throws IOException {
String line;
BufferedReader in;
in = new BufferedReader(new InputStreamReader(System.in));
boolean finnish = false, reenter = false;
while(finnish == false) {
int i;
for(i = 0; i <= 7; i++) {
System.out.println("enter a name");
name[i] = in.readLine();
System.out.println("enter a day");
String day = in.readLine();
System.out.println("enter a month");
String month = in.readLine();
System.out.println("enter a year");
String year = in.readLine();
date[i] = day + "/" + month + "/" + year;
String offenceEnter[] = new String[3];
String offenceType[] = {"Assault","Arson","Theft"};
int l;
for(l = 0; l <= 2; l++) {
System.out.println("is there offence " + offenceType[l]);
offenceEnter[l] = in.readLine();
if(offenceEnter[l] == "yes") {
offence[i] = offenceType[l];
}
}
}
}
in.close();
}
}