Friday, June 6, 2014

NetBeans The type of [method call] is erroneous

While you are working with your code, the NetBeans IDE sometimes unexpectedly shows an error sign. When hovering the cursor over the place underlined with a curly red line, the message says that the type of <mehtod> is erroneous.

This type of error sign occurs in the following situations
1. When a final method in the super class is called from a subclass.
         public class SuperPowerful {
                   public final String getTheString() {
                             return "Super class final method is called";
                   }
         }

         public class SubPowerful  extends SuperPowerful {
                   public void printString() {
                             //The error sign shows on this line of code
                             String str = getTheString(); 
                             System.out.printlin(str);
                   }
          }

2. When creating a class instance using a return type of an interface that is not directly implemented by this class, but is implemented by its super class.
          public interface SunRisingInterface {
                    public void sunIsRising();
          }

          public class GeneralSunRise implements SunRisingInterface {
                   public void sunIsRising() {
                             System.out.println("get ready to watch sun rising!!!");
                   }
          }

          public class SummerSunRise extends GeneralSunRise {
                     public static void main(String [] args) {
                               //The error sign shows on this line of code
                               SunRisingInterface sri = new SummerSunRise();
                               sri.sunIsRising();
                     }
          }

However the code compiles and runs just fine. You can either ignore the error sign, but if your feel uncomfortable to work while there is an error sign you may fix the problem as stated below.

To fix this problem

A. Remove and add back the jar containing the super class to the project library/path if the super class and sub class are contained in two different projects. Let's say that the super class is in project A and the sub class is in project B.
  1. Right-click on project B and select "Porperties".
  2. Click "Libraries" on the left under Categories.
  3. Select the library or the jar of project A in the right pane and click the "Remove" button to remove it.
  4. Click "OK" to close the window.
  5. Restart NetBeans.
  6. Repeat steps 1 and 2.
  7. Click the "Add Library" or "Add JAR/Folder" button to add the library or the jar of project A back to project B.
B. Remove the final  keyword from the method in the super class.

C. Change public class SummerSunRise extends GeneralSunRise to public class SummerSunRise extends GeneralSunRise implements SunRisingInterface.
       
---------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

2 comments: