Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

non-static method cannot be referenced

Status
Not open for further replies.

ojiga

Programmer
Aug 4, 2005
2
RU
/*
* IBS send encripted XML
*/

// import needed packets
import java.text.*;
import java.awt.*;
import java.applet.*;
import bsc.security.*; // <---- external .JAR

public class XMLDataWithSignature
{
public static String xmlToSign = "zzzzzzzz";
public static String XML64;

public static void main(String args[])
{
XML64 = bsc.security.Secto.BASE64Encode(xmlToSign);
System.out.println("hahahha");
}


}




-----------------------

C:\Program Files\JDK\bin>"C:\Program Files\jdk\bin\javac.exe" -verbose -d C:\MY_DOCS\CODiNG\JAVA\IBS_BASE64 -classpath "C:\Program Files\JDK\jre\lib\i18n.jar;C:\Program Files\JDK\jre\lib\jaws.jar;C:\Program Files\JDK\jre\lib\rt.jar;C:\Program Files\jdk\lib\dt.jar;C:\Program Files\jdk\lib\tools.jar;C:\Program Files\jdk\lib;C:\Program Files\JDK\jre\lib;C:\MY_DOCS\CODiNG\JAVA\IBS_BASE64\security.jar;" -g -deprecation XMLDataWithSignature.java
[parsing started XMLDataWithSignature.java]
[parsing completed 180ms]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/lang/String.class)]
[checking XMLDataWithSignature]
[loading C:\MY_DOCS\CODiNG\JAVA\IBS_BASE64\security.jar(bsc/security/Secto.class)]
XMLDataWithSignature.java:18: non-static method BASE64Encode(java.lang.String) cannot be referenced from a static context
XML64 = bsc.security.Secto.BASE64Encode(xmlToSign);
^
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/lang/System.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/io/OutputStream.class)]
[total 6028ms]
1 error

-----------------
how execute the non-static method from static class ???
 
If the BASE64Encode method is not static, you'll have to create an instance of the Secto class to use it.

Code:
public class XMLDataWithSignature
{
        public static String xmlToSign = "zzzzzzzz";
        public static String XML64;

        public static void main(String args[])
        {
                Secto obj = new Secto();
                XML64 = obj.BASE64Encode(xmlToSign);
                System.out.println(XML64);
        }
}

BTW, in Java, methods and variables begin with lower case letters by convention.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
[parsing started XMLDataWithSignature.java]
[parsing completed 130ms]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/lang/String.class)]
[checking XMLDataWithSignature]
[loading C:\MY_DOCS\CODiNG\JAVA\IBS_BASE64\security.jar(bsc/security/Secto.class)]
XMLDataWithSignature.java:18: Secto() has private access in bsc.security.Secto
Secto obj = new Secto();
^
XMLDataWithSignature.java:19: non-static method BASE64Encode(java.lang.String) cannot be referenced from a static context
XML64 = bsc.security.Secto.BASE64Encode(xmlToSign);
^
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/lang/System.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading C:\Program Files\jdk\jre\lib\rt.jar(java/io/OutputStream.class)]
[total 7461ms]
2 errors

-----------------------
*ggg* excuse me.... now, how get access 2 private Secto??
 
Well, without knowing about this Secto class, I'm shooting in the dark here.

It looks as if the constructor in Secto is private. This is usually done in the 'Singleton' pattern, so there may be a newInstance method on the Secto class which gets you new instances. With seeing this class, or any documentation, I'm not going to be much help.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top