Java Video Tutorial 35

Common Java ErrorsOne of you guys asked me to do a tutorial on Fixing Java Errors. I thought it was a good idea, so here I’ll show you over 30 common Java errors.

Sometimes it is hard to figure out what Cannot be Resolved, Syntax Error on Token, or Method is not Visible mean. But, after watching this video you should better understand.

Also, you’ll learn how to get Eclipse to help you fix Java errors.

If you like videos like this tell Google
To make me extra happy, feel free to share it

Code from the Video

import java.lang.Math.*;

public class Lesson35{
	// ERROR 1: Cannot make a static reference to the non-static method
	// SOLVED: You can't call a non static method from a static method
	// private void printSomething(){
	private static void printSomething(){
	// ERROR 2: Unresolved compilation problem
	// SOLVED: Pay attention to Eclipse Errors
	// Int BigNumber = 100000;
		// ERROR 3: A string literal isn't properly closed
		// SOLVED: Pay attention to Eclipse
		//String something = "A string error
				//is occurring";
	} // If this is missing you get ERROR 2
	// ERROR 4: Exception in thread "main" java.lang.NoSuchMethodError: main
	// SOLVED: Make sure you type the main function correctly
	// public static void main(String args){ // This is Wrong
	public static void main(String[] args){
		// ERROR 5: Can't be resolved to a variable
		// SOLVED: Pay attention to Eclipse
		// printsomething; // This is Wrong
		// ERROR 6: Type mismatch Can't convert from int to String
		// SOLVED: Convert the integer
		int number = 12;
		// String anotherNum = number; // This is Wrong
		String anotherNum = Integer.toString(number);
		// int number = Integer.parseInt(anotherNum); // Convert from string to int
		// ERROR 7: Can't be resolved to a type
		// SOLVED: import the dimension library
		// Dimension dim = new Dimension();
		// ERROR 8: Method is undefined
		// SOLVED: Make sure methods are in the class
		double pi = 3.14;
		// long randLong = Lesson34.round(pi); // The wrong way
		// ERROR 9: Can't invoke method
		// SOLVED: Understand how methods work
		long randLong = Math.round(pi); // The right way
		// randLong = pi.round(); // Wrong way
		// ERROR 11: The method is not applicable for the arguments
		// SOLVED: Provide the right arguments in the right order
		// getStuff(1.234, 5); // Wrong Way
		getStuff(1,5.0); // Right Way
		// ERROR 12: Syntax error on token ",; expected
		// SOLVED: Understand how methods are called in Java vs. other languages
		// double sumNum = addThem(LessonFive,1,2); // Wrong Way
		double sumNum = LessonFive.addThem(1,2);
		// ERROR 13: Syntax error on token '=='
		// SOLVED: = is different from ==
		// int value == 1;
	// ERROR 10: Can't be resolved to a type
	// SOLVED: Always provide the type in methods
	/* public static void getStuff(number1, number2){
	} */
	// ERROR 14: Return type for method is missing
	// SOLVED: Provide a return type or void
	public static void getStuff(int number1, double number2){
		// ERROR 15: Syntax error on token ",[ expected
		// SOLVED: Understand how arrays are defined in Java
		// int[] intArray = new [10,10]int; // Wrong Way
		int[][] intArray = new int[10][10];
		// ERROR 16: The method is not visible
		// SOLVED: You can't private methods which are declared in 
		// another class. private static void getFileInfo()
		// Lesson33.getFileInfo(); // Wrong Way
		// ERROR 17: Local variable may not have been initialized
		// SOLVED: Always give variables default values
		String howMany = "10";
		// String howMany; // Wrong Way
		// ERROR 18: Cannot be Resolved
		// SOLVED: Understand that arrays and strings use a 
		// different version of length
		// System.out.println(howMany.length); // Wrong Way
		// System.out.println(intArray.length()); // Wrong Way
		// ERROR 19: Prefix Operator vs. Postfix Operator
		int xInt = 1, yInt = 1;
		xInt = yInt++; // Passes the original value of yInt before incrementing
		System.out.println("xInt: " + xInt); 
		// ERROR 20: Not calling break at end of case
		int day = 1;
		switch (day){
			case 1: System.out.println("Monday");
			case 2: System.out.println("Tuesday");
			case 3: System.out.println("Wednesday");
			case 4: System.out.println("Thursday");
			default: System.out.println("Friday");

10 Responses to “Java Video Tutorial 35”

  1. mr.roshik says:

    thanks for the tutorial, will u pls also make a tutorial on IE errors and how to fix it?

  2. mr.roshik says:

    Thanks , i got it. i have got some new issues , pls help me to understand when you are free.
    1. position property can be used to set the position of an element, so why float is important to learn ? is it true that using position property is a bad practice when we have chance to use float property ?
    2. suppose there are two class named “something” and “nothing”,
    wht is difference between .something+.nothing{property:value;} and .something, .nothing {property:value;}?
    as far as i know this .something, .nothing {property:value;} is called Grouping Selectors.
    3. display:inline-block; what does it mean ?
    4. would u please give me a practical example of display:block property ?
    i know u are a css geek but very helpful, so i have asked a lot , dont mind, take care

    • admin says:

      1. I like to use float to get all of the page elements to wrap around it. I don’t like to use absolute positioning. I just think a more liquid layout looks better. That is just an opinion.
      2. #idName.className would target an element with both a class name and id name. When you put a space between these you are targeting elements under the first element. So, #idName .className means target all elements with the class name className that are decendents of idName
      3. inline-block doesn’t force line breaks after the element. Since it is still a block item you can set width, height, top and bottom margins / paddings
      4. block elements force a line break and allow you to define width, height, top and bottom margins / paddings

  3. frank says:

    pls i want tutorial on how to deploy a java application and a print method for printing screens in a printer

  4. Sham says:

    Hello Derek,

    Please let me know,
    What is java-jni priority in your priority list?

    You are jumping in every possible technology(SAMSUNG SDK), I want you to come back to our old C / C++ sooooooooooon!!

    I was able to reach till java # 35 now, with all your programs written and compiled.

    • Derek Banas says:

      I’m going to finish Samsung this month. Then I’ll finish up C, Inkscape, Google Maps with Android and a few other Android technologies. At that point I’ll transition into Android graphics, interfaces and games. I’ll hold a vote on whether the tutorial that will come out along with the Android stuff will be C++, or J2EE.

Leave a Reply

Your email address will not be published.