x10102
x10102

Reputation: 18

Cant access Method From Instance of class from another package

Im making a program in java, that uses multiple java files and packages in NetBeans Error is Here:

package hardware;
import software.Firmware;
/**
 *
 * @author x1010
 */
public class Router {
Firmware os = new Firmware ();
os.UkazTypZarizeni();
}

Class Firmware:

package software;

import test.Shrt;

/**
*
 * @author x1010
*/
public class Firmware  {
private final Shrt s = new Shrt();
public String TypZarizeni = null;
public void UkazTypZarizeni () {
 if(TypZarizeni != null) {  
    s.print("Typ Zarizeni = " + TypZarizeni); 
   } else {
     s.print("Typ Zarizeni: Nezname Zarizeni");
   }

  }
  public void NastavitTyp (String TypA) {
  TypZarizeni = TypA;
  s.print("Typ Zarizeni Zmenen na " +  TypA);
  }   
 }

In Class Router, on the line os.UkazTypZarizeni(); It says: Package os does not exist. Help please! And sorry for my terrible English and the program in czech >]

Upvotes: 0

Views: 35

Answers (1)

Damon
Damon

Reputation: 64

You have to provide a method name in router class. You can not call the method of another class without writing a method in the calling class.

    package hardware;
    import software.Firmware;
    /**
     *
     * @author x1010
     */


 public class Router {

    void callUkazTypZarizeni {  //TODO correct the method name.

    Firmware os = new Firmware ();
    os.UkazTypZarizeni()
    }
}

Please let me know if your are still facing the issues.

Upvotes: 1

Related Questions