Errors

This page is a list of errors you encounter and possible ways to solve them.
 * Keep in alphabetical order!**

Just a note, Mr.Meermans has said this before, but sometimes the best way to find an error is to have a new set of eyes to look at your code, they might catch something that you missed, so dont be afraid to ask for help. //**Types of Errors:**// Logic Error - this is when the program compiles correctly, and will run without error, but does not do the intended purpose that it was meant to do. This is usually caused by an error caused by the programmer. Logic errors include multiplying when you should be dividing, adding when you should be subtracting, and opening and using data from the wrong file. code ex.      System.out.println("5 + 3"); //this would print "5 + 3" but you might be trying to print "8" //the real code to print "8" is as follows

System.out.println(5 + 3);

code Syntax error - An instruction that does not follow the programming language rules and is rejected by the compilier. Error in the form of the statement. (mispelled word, unmatched parenthesis, comma out of place, etc.)

code ex.      Int i == 0         //wrong int i = 0;        //very right code Runtime Error - this error occurs when the program is executed, and will usually result in the program returning a mass of error messages to the user. This can happen even though everything is done correctly before compilation of the code. Runtime errors may occur when trying to divide a variable that contains value of 0 or trying to open a file that does not exist. code ex.      int i = 5/0;       //the computer recognizes this code only after you try to compile it                          //and it's considered illegal for any division by a number "0" code

illegal start of expression- This occurs when part of the code is missing, and the compiler can not tell where you are beginning a new statement. code format="java5" public void recipe {  if chocolate == vanilla)  //the if statement is missing a parenthesis.   {     System.out.print("Chocolate LOVE");   } } code __possible loss of precision__- happens sometimes when you try to store a double into an integer, vice versa. To fix this, you must **cast** the value.

code format="java" public void number(int x, double y) { y = (double)x + 2.4 } code __';' expected__ - a semicolon is missing from a line of code. (Note: This type of error would also be known as a syntax error)

code format="java5" public void example {  System.out.print("Hi") //There should be a semicolon after the line above }

code __Other types__ Just like when using the "==" operator, it is easy to forget to use double ampersands (&&), and vertical lines (||). This can cause many easily overlooked problems. Reminder: Double Ampersands-&&-Are used for the "and" operation. Double Vertical Lines-||-Are used for the "or" operation. These are fairly easy to forget, just like the semi-colon and parenthesis

__Remember__ Sometimes, the reason why the particular code isn't working is not made clear by BlueJay's little comments. To avoid getting yourself confused about what needs fixing, every so often just stop writing the code and take a look at what you've written. Read it clearly to yourself and make sure that it at least looks like it will do what it is supposed to. Then, if you can, go ahead and compile what you have and then run it to make sure no little detail has been forgotten. __DO NOT WRITE THE WHOLE CODE AT ONE TIME!!!__ This increases the chances that you will be confused if something is wrong. If it helps, write it out in pseudo-code first.