Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

non static method cannot be referenced from static context

Hi all..

I want to make a Java program which calls (nonstatic) function from another java file, but I always get the error msg :

socket.java:40: non-static method sign(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String) cannot be referenced from a static context
  e.signature = SignatureGen.sign("a", "b", "c", "d",  "e");
                                                                                                      ^

my current program is:

public class socket {
  String signature;
 public static void main(String[] args) {

  socket e = new socket();
  e.signature = SignatureGen.sign("a", "b",  "c",  "d",  "e");
  System.out.println(e.signature);
   
  }
}

The sign class is in SignatureGen.java file, and may not be changed to static..

Anybody can help me? :) thankss..
0
pipinana2002
Asked:
pipinana2002
  • 3
  • 3
1 Solution
 
amit_chauhanCommented:
It seems sign method is a not a static method.
Change this line :

e.signature = SignatureGen.sign("a", "b",  "c",  "d",  "e");

to

SingatureGen gen = new SingatureGen ();
e.signature = gen.sign("a", "b",  "c",  "d",  "e");


Hope that helps
Thanks
Amit
0
 
pipinana2002Author Commented:
Hi again..

i change my code already acording to your opinion.. but now there is errors:

socket.java:39: cannot resolve symbol
symbol  : class SignatureGen
location: class socket
  SignatureGen gen = new SignatureGen ();
  ^
socket.java:39: cannot resolve symbol
symbol  : class SignatureGen
location: class socket
  SignatureGen gen = new SignatureGen ();
                         ^

how to correct this probs ya? thankss.. :):)
0
 
pipinana2002Author Commented:
whoopss.. sorryy.. juz now i mistyped the command :) tks so much for your help :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
amit_chauhanCommented:
You welcome.
But you reduced the points !!

Amit
0
 
pipinana2002Author Commented:
Hi.. i just realize u said that i reduce the points? i just accept your answer.. how come the points reduced ya? i thought that we cannot reduce the points we have entered?

so sorryy.. i really don't know how that can happenn..
0
 
amit_chauhanCommented:
Dont worry abt it. Even I didnt knew it until I asked this question to the moderators and they gave me some explanation. You basically havent reduced the points, its just displaying the points it will cost for non-members to view this question, something like that crap :)
Check it here :
http://www.experts-exchange.com/Community_Support/Feedback/Q_20570513.html
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now