Introduction: BlueJ Problems
Hello Ladies and Gentlemen,
In This "Instructable" You will learn how to solve common mistakes, identify blue J errors and many others. I really want to say "THANKS" for all the support you guys are showing, like, really!!! When I came here I was expecting to get like 5 views on the previous one but ,for less than a day, I got more than 20 views, and that is crazy, again ,Thank you for all the support. If you guys find some uncommon mistakes, problems, let me know, I might be able to solve them...
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
The one, not that very common mistake, a programmer might do, is to make an instance variables without any parameters (no public, no double, no int, etc...) . The mistake ( expected) tells us that the instance variable( "x") is unknown. The Program doesn't know if "x" is a number or a letter. It doesn't know if other people can see it or not.
So In order to fix this:
- You must tell the computer if the variable is either a number, or a letter by putting int, (double for a fractions) or string(including both, a letter or a number).
- Make sure it's a private( when the program runs, no one can see it), or a public(when the program runs, everyone can see it).
Note: The error can be fixed, if needed, using only step Number. 1, You don't really need to do step Number 2 in order to fix the error.
Step 2: Incompatible Types
As seen on the example above the instance variable "x"(which is an Integer) is converted to "X" (which is a double) making The error "Incompatible Types: Possible lossy conversions from double to int. "As we all know" int is only a "whole number", and double can be a "whole number" and a "fraction", which leads to the solution that integer is less than a double (int < double). In a way, the program tells you that you can not store the "data" of a variable into the "data of a BIGGER variable. It's like have 8 GB into a 6GB flash drive, it won't just work...
How to solve the error And/or prevent it:
Make sure the instance variable (public int x) is bigger than the variable into the method( double X), by making the instance variable (public int x) a double (public double x) and (optional) making the variable in the method (double X) an integer(int X).
Step 3: Invalid Method Declaration
The most common mistake and hard time programmers have is to describe what the method to be. The method is like the instance variable, it can be public, private, int, and double. But( as I said on the previous "instructable") The method can include void and/or static. but in this case, using one of these parameters will lead to a problem where the only solution is to delete the variable y, but we want to say that "x" is added to "y". The error says "return type required". We have the method returning something, but if we look close to the error it says "return TYPE required". And by "type" the code doesn't mean void, and/or static. It means we need to tell the method that is adding number by writing: "int" and/or "double" leading to the error solved...