1

I have a class named AttachmentsBean which has a method named showUploadDialog(). In another class named UploadBean, when I execute the following code :

if(count=0)
{
   return AttachmentsBean.showUploadDialog();
}   

I get the error:

"Non-static method cannot be referenced from a static context".

Please suggest.

Bart
  • 9,925
  • 7
  • 47
  • 64
Aman Kumar
  • 11
  • 3

3 Answers3

1

AttachmentsBean.showUploadDialog() is appropriate only if showUploadDialog is declared with the static modifier.

hearnden
  • 522
  • 2
  • 8
1

The signature of showUploadDialog() should be like this

public static <return type> showUploadDialog() {
 //Do something
}
Ahmed
  • 184
  • 7
0

You can use AttachmentsBean.showUploadDialog() only if showUploadDialog declared as static:

public static ... showUploadDialog() {
  ...
}

if you need to call no-static method, you need at first create AttachmentsBean object, for example:

if(count=0)
{
   return new AttachmentsBean().showUploadDialog();
}   
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59