Ok i have of course read all about this error, It means that what im using is pointing to a null value.
Although i cannot see the problem, The first class file gets the double values from the textfile for the data, It then sais ok
data[i] = Graph.VARIABLE;
Although even tho i'm passing it between class's i have named both the data array the the variables being passed the values static.
The question is now why is it saying nullpointer? code:
import java.io.FileReader; import java.util.Scanner; public class Graph { public static double Sun, Mon, Mer, Mar, Ven, Jup, Sat, Ura, Nep, MC, Cnj, Sxt, Tri, Opp, Sqr, SSq, Sun_Mon, Sun_Jup, Sun_Nep, Sun_Ven, Sun_Ura, E, X, L, Asc; public String[] storage = new String[10000]; public String[] vp1 = new String[5000]; public String[] asp = new String[5000]; public String[] vp2 = new String[5000]; public String[] exl = new String[5000]; public String[] time = new String[5000]; public double[] score = new double[5000]; public int lines; public Graph() throws Exception{ //Run Methods: addGraph(); } public void addGraph() throws Exception{ FileReader file = new FileReader("AD Converter/temp/program.txt"); Scanner scan = new Scanner(file); int i = 0; int m = 0; while (scan.hasNext()) { storage[i] = scan.next(); //System.out.println(storage[i] + " " + i); lines = i; i++; } for(int a = 0; a <= lines; a = a + 6){ vp1[m] = storage[a].toString(); //System.out.println(vp1[m] + m); m++; } m = 0; for(int a = 1; a <= lines; a = a + 6){ asp[m] = storage[a].toString(); //System.out.println(asp[m] + m); m++; } m = 0; for(int a = 2; a <= lines; a = a + 6){ vp2[m] = storage[a].toString(); //System.out.println(vp2[m] + m); m++; } m = 0; for(int a = 3; a <= lines; a = a + 6){ exl[m] = storage[a].toString(); //System.out.println(exl[m] + m); m++; } m = 0; for(int a = 4; a <= lines; a = a + 6){ time[m] = storage[a].toString(); //System.out.println(time[m] + m); m++; } m = 0; for(int rate = 0; rate <= lines; rate++){ double vp1t = getValue(vp1[rate]); double vp2t = getValue(vp2[rate]); double aspt = getValue(asp[rate]); double exlt = getValue(exl[rate]); double prev = 0.0; if(exl[rate].contains("\\(E\\)")){ score[rate] = prev; } else if(exl[rate].contains("\\(L\\)")){ score[rate] = vp1t + vp2t / 2 * aspt * exlt; if(score[rate] < 0.0){ score[rate] = score[rate] * 2; } } score[rate] = vp1t + vp2t / 2 * aspt * exlt; System.out.println(score[rate]); } } public double getValue(String convert){ double value = 0.0; // DEBUGGING: Test the value of Sun due to saying null pointer exception. // ERROR IS THIS LINE: System.out.println(Sun + " Value of sun"); if(convert.equals("Sun")){ value = Sun; return(value); } else if(convert.equals("Mon")){ value = Mon; return(value); } else if(convert.equals("Asc")){ value = Asc; return(value); } else if(convert.equals("Mer")){ value = Mer; return(value); } else if(convert.equals("Mar")){ value = Mar; return(value); } else if(convert.equals("Ven")){ value = Ven; return(value); } else if(convert.equals("Jup")){ value = Jup; return(value); } else if(convert.equals("Sat")){ value = Sat; return(value); } else if(convert.equals("Ura")){ value = Ura; return(value); } else if(convert.equals("Nep")){ value = Nep; return(value); } else if(convert.equals("MC")){ value = MC; return(value); } else if(convert.equals("Cnj")){ value = Cnj; return(value); } else if(convert.equals("Sxt")){ value = Sxt; return(value); } else if(convert.equals("Tri")){ value = Tri; return(value); } else if(convert.equals("Opp")){ value = Opp; return(value); } else if(convert.equals("Sqr")){ value = Sqr; return(value); } else if(convert.equals("SSq")){ value = SSq; return(value); } else if(convert.equals("Sun/Mon")){ value = Sun_Mon; return(value); } else if(convert.equals("Sun/Jup")){ value = Sun_Jup; return(value); } else if(convert.equals("Sun/Nep")){ value = Sun_Nep; return(value); } else if(convert.equals("Sun/Ven")){ value = Sun_Ven; return(value); } else if(convert.equals("Sun/Ura")){ value = Sun_Ura; return(value); } else if(convert.equals("(E)")){ value = E; return(value); } else if(convert.equals("(L)")){ value = L; return(value); } else if(convert.equals("(X)")){ value = X; return(value); } else { return(value); } } }
What i'm actualy doing is splitting a text file into 5 arrays. each collumn in the textfile is in a new array.
Now they are strings.. So im passing the strings to the new method. and the new method is suppose to say if the array contains this string then return this value.
I've marked the line giving me the problem above with a comment. "// ERROR ON THIS LINE:"
Its outputting to a double which should be correct, here is my console when i debug:
3.0 3.0 3.0 3.0 3.0 0.4000000059604645 0.4000000059604645 0.4000000059604645 1.2000000476837158 1.399999976158142 1.399999976158142 2.0 1.5 2.75 2.5 2.5 1.8999999985098839 1.25 1.25 2.100000001490116 2.75 1.625 1.8499999977648258 3.125 2.0 2.300000011920929 2.375 2.150000002235174 1.0999999642372131 0.875 2.0 1.699999988079071 2.900000035762787 1.25 3.399999976158142 2.75 1.449999988079071 0.6000000238418579 2.550000011920929 1.75 2.25 0.875 2.900000035762787 3.125 3.25 1.0999999642372131 2.3499999940395355 2.75 2.75 1.6500000059604645 1.25 1.25 2.150000002235174 2.75 3.0 1.8499999977648258 1.25 2.0 2.0 2.0 1.699999988079071 2.0 2.300000011920929 1.25 1.25 2.75 2.75 1.8499999977648258 2.8250000178813934 2.150000002235174 2.25 2.0 1.1749999821186066 2.375 2.5 2.2000000029802322 1.75 2.0 1.625 2.0 1.5 1.399999976158142 1.7999999970197678 2.0 2.600000023841858 1.6500000059604645 3.0 2.3499999940395355 0.9500000178813934 1.0 1.1749999821186066 3.0499999821186066 2.8250000178813934 1.625 3.5 2.375 2.4500000178813934 1.5499999821186066 0.5 3.0499999821186066 0.9500000178813934 1.75 2.0 2.25 2.0 1.5499999821186066 3.100000001490116 2.600000023841858 2.4500000178813934 1.399999976158142 3.0 2.5249999910593033 3.0 1.4750000089406967 2.2000000029802322 0.5 1.0 1.0 3.5 1.7999999970197678 1.625 1.8499999977648258 2.0 2.375 2.150000002235174 2.0 1.4750000089406967 1.25 2.5249999910593033 1.300000011920929 2.75 3.100000023841858 2.699999988079071 2.5 2.375 2.0 0.8999999761581421 1.625 2.0 2.375 2.150000002235174 0.875 1.5 1.625 1.8499999977648258 3.125 3.900000035762787 2.75 1.25 1.625 2.375 2.600000023841858 3.125 0.875 1.399999976158142 1.25 1.25 2.75 2.75 1.8499999977648258 2.699999988079071 2.150000002235174 1.300000011920929 1.75 1.8999999985098839 2.0 2.25 2.100000001490116 0.7999999523162842 2.0 3.200000047683716 2.699999988079071 2.75 2.75 1.5 1.25 1.300000011920929 1.25 2.150000002235174 2.75 2.5 1.1749999821186066 1.8499999977648258 1.25 2.8250000178813934 1.625 2.375 1.25 2.0 2.75 2.0 2.8250000178813934 2.5 2.0 1.1749999821186066 2.375 2.0 2.25 2.100000001490116 1.625 1.5 1.5499999821186066 1.75 1.8999999985098839 2.4500000178813934 0.4750000089406967 1.5 2.099999964237213 1.5 2.5 2.5 2.5 1.8999999985098839 1.25 1.5 2.100000001490116 2.75 2.75 2.0 2.4500000178813934 1.25 2.0 1.5499999821186066 1.4750000089406967 2.5249999910593033 0.6000000238418579 2.625 1.449999988079071 3.399999976158142 2.550000011920929 1.75 2.25 2.600000023841858 1.399999976158142 2.5249999910593033 3.3499999940395355 2.5 2.5 1.4750000089406967 1.5 1.5 2.100000001490116 3.125 1.8999999985098839 0.875 1.625 2.375 2.0 1.699999988079071 2.0 2.300000011920929 0.875 2.0 2.550000011920929 3.125 2.375 2.0 1.449999988079071 2.25 1.625 2.0 1.5 1.7999999970197678 1.75 2.5 2.2000000029802322 1.399999976158142 2.600000023841858 1.6500000059604645 1.0 2.3499999940395355 2.0 3.0 2.5 0.5 2.300000011920929 3.5 1.699999988079071 2.699999988079071 1.300000011920929 1.75 2.0 2.25 2.0 2.6500000059604645 2.900000035762787 1.0999999642372131 2.3499999940395355 1.0 1.0 1.6500000059604645 3.5 3.0 3.0 1.7999999970197678 -0.1249999850988388 2.2000000029802322 0.5 2.0 1.0999999642372131 2.0 4.5 2.900000035762787 4.0 1.300000011920929 0.8999999761581421 2.699999988079071 2.25 2.0 3.100000023841858 1.5 1.75 2.0 2.25 2.100000001490116 2.5 1.75 1.8999999985098839 2.5 4.0 2.7999999970197678 1.5 2.0 2.0 2.75 1.399999976158142 1.25 2.600000023841858 3.0499999821186066 0.875 0.9500000178813934 3.125 1.75 1.8999999985098839 2.25 3.200000047683716 2.100000001490116 0.7999999523162842 1.300000011920929 2.5 2.5 1.5 2.699999988079071 1.5 1.5 2.100000001490116 0.9500000178813934 3.125 2.5 1.8999999985098839 3.0499999821186066 0.875 1.25 2.0 2.75 2.0 2.550000011920929 2.0 1.5 1.449999988079071 2.25 2.5 2.375 2.150000002235174 1.75 2.0 1.625 1.8499999977648258 1.5 1.5 Exception in thread "main" java.lang.NullPointerException at Graph.getValue(Graph.java:99) at Graph.addGraph(Graph.java:75) at Graph.<init>(Graph.java:22) at newFile.<init>(newFile.java:17) at calculate.<init>(calculate.java:15) at updateData.<init>(updateData.java:18) at correctData.<init>(correctData.java:25) at correctData.main(correctData.java:228)
Any ideas ?