Me and Null Pointer Exception are having issues...
So I am a bit over my head, been learning Java for 6 days now and have written my first code longer than 30 lines (actually I am somewhere around 300 lines right now with console only input and output, also only about 80% done the coding that will make the program do it's job, still have to clean it, add error codes and error prevention, add code for unexpected entries, add a graphical interface... It is something I will keep working on as I learn more)
I used to do some very light basic programming in 1982-1986, took 1 basic class and 1 cobol class in college in 1997/98, also spent about 2 years hand coding html in 1996-98.
General Java questions:
my problem with java so far has been it frequently calls my variables by types other than what they are, from web/forum searches I am learning the problem is caused by certain commands I am using force specific variable types, something I can avoid (mostly) if I understood one thing:
is memory pre-allocated for a variable based off of its type?
example would be the "byte" is enough bits reserved for the maximum storage space a byte could use, allocated during the application run, or only the space that is actually used when it is assigned a value?
What I am getting at above is why would you use the int type in a program that only requires 1 or 2 digit numbers? it obviously takes up more memory space than a byte would.
now on to why I am actually posting this here:
I am using Eclipse, and I received a java.lang.NullPointerException error, when I clicked on the part of the error showing the line number it took me to a commented line:
//assign user input to variable
obviously not a Null Pointer issue, the two lines above are:
//prompt the user to enter if they want to drop the lowest
out.print("Do you want me to drop the lowest? (y or n) ");
and the two lines below are:
yOrN = userInput.findInLine(".").charAt(0);
the only thing I could think of was the variable yOrN was causing the issue, so I added teh following line about 15 or so lines up in the code:
//attempting to resolve a null pointer error
yOrN = 'n';
recompiled and received the same error.
the variable yOrN was initialized as type "char"
There are other parts of my code where I received some weird responses from the compiler, but I was able to do things that to me made no sense, but made the error go away and the new code appears to do same thing, just with more code used to do it.
I'll post the entire code block I have, if needed, but I don't really want to. (not that it is super secret or anything, but I know my coding style sucks still and don't need to put it on the internet for it to be stored for eternity on some web archive database.)