Can't make static reference to method

hi all,
pls help me in the code i'm getting
" can't make static reference to method....."
kindly help me
the following code gives the error:
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.io.*;
import java.io.IOException;
import java.io.LineNumberReader;
public class client
static String vcno;
static String vpin;
static String vamt;
static String vordid;
static String vptype;
//static String vreq;
static String vreq = "1";
static String vorgid;
static String vm1;
static String vs1;
static String vqty1;
static String vm2;
static String vs2;
static String vqty2;
static String vm3;
static String vs3;
static String vqty3;
static String vm4;
static String vs4;
static String vqty4;
public static void main(String args[])
try
ServerIntf serverintf=(ServerIntf)Naming.lookup("rmi://shafeeq/server");
int c;
StringBuffer sb;
FileReader f1=new FileReader("c:/testin.txt");
sb=new StringBuffer();
int line=0;
while ((c=f1.read())!=-1) {
sb.append((char)c);
LineNumberReader inLines = new LineNumberReader(f1);
String inputline;
String test;
while((inputline=inLines.readLine())!=null)
line=inLines.getLineNumber();
switch(line)
case 1: {
vcno = inLines.readLine();
System.out.println(vcno);
case 2: {
vpin = inLines.readLine();
System.out.println(vpin);
case 3: {
vptype = inLines.readLine();
System.out.println(vptype);
case 4: {
vamt = inLines.readLine();
System.out.println(vamt);
case 5: {
vordid = inLines.readLine();
System.out.println(vordid);
case 6: {
vorgid = inLines.readLine();
System.out.println(vorgid);
     case 7: {
vm1 = inLines.readLine();
System.out.println(vm1);
     case 8: {
vs1 = inLines.readLine();
System.out.println(vs1);
     case 9: {
vqty1 = inLines.readLine();
System.out.println(vqty1);
     case 10: {
vm2 = inLines.readLine();
System.out.println(vm2);
     case 11: {
vs2 = inLines.readLine();
System.out.println(vs2);
case 12: {
vqty2 = inLines.readLine();
System.out.println(vqty2);
case 13: {
vm3 = inLines.readLine();
System.out.println(vm3);
     case 14: {
vs3 = inLines.readLine();
System.out.println(vs3);
case 15: {
vqty3 = inLines.readLine();
System.out.println(vqty3);
case 16: {
vm4 = inLines.readLine();
System.out.println(vm4);
case 17: {
vs4 = inLines.readLine();
System.out.println(vs4);
case 18: {
vqty4 = inLines.readLine();
System.out.println(vqty4);
f1.close();
FileWriter f2=new FileWriter("c:/testout.txt");
String t;
t=ServerIntf.add(vcno,vpin,vamt,vordid,vptype,vreq,vorgid,vm1,vs1,vqty1,vm2,vs2, vqty2,vm3,vs3,vqty3,vm4,vs4,vqty4);
String str1 = " >>";
str1 = t + str1;
f2.write(str1);
System.out.println('\n'+"c:/testout.txt File updated");
f2.close();
catch(Exception e)
System.out.println("Error " +e);

Yes, ServerIntf is the interface type. The instance serverIntf. You declared it somewhere at the top of the routine.
So what you must do is call t=serverIntf.add(...)This is probably just a mistype.

Similar Messages

  • Can't make static reference to method while it is static

    Hello, can somebody please help me with my problem. I created a jsp page wich includes a .java file I wrote. In this JSP I called a method in the class I created. It worked but when I made the method static and adjusted the calling of the method it started to complain while i didnt make an instance of the class. the error is:Can't make static reference to method
    here is the code for the class and jsp:
    public class PhoneCheckHelper {
    public static String checkPhoneNumber(String phoneNumber) {
    String newPhoneNumber ="";
    for(int i=0; i<phoneNumber.length(); i++) {
    char ch = phoneNumber.charAt(i);
    if(Character.isDigit(ch)) {
    newPhoneNumber += String.valueOf(ch);
    return newPhoneNumber;
    <html>
    <head>
    <title>phonecheck_handler jsp pagina</title>
    <%@page import="java.util.*,com.twofoldmedia.text.*, java.lang.*" %>
    </head>
    <body>
    <input type="text" value="<%= PhoneCheckHelper.checkPhoneNumber(request.getParameter("phonenumberfield")) %>">
    </body>
    </html>

    Go over to the "New to Java" forum where that message is frequently explained. Do a search if you don't see it in the first page of posts.

  • HT1689 Using my iPad how can I make paypal my payment method on iTunes??

    Using my iPad how can I make paypal my payment method on iTunes??

    When you open a word document, on the bottom of the keyboard next to the spacebar there should be a microphone. Tap it and speak what you want into it then tap it again to stop.

  • Can one combine static and instance methods?

    Hi,
    Can one define a method so that is can be used as both a static or an instance method?
    Basically I'm trying to simplify my class to so that I can call a method either statically with parameters or instantiated using it's own attributes.
    In other words, I'm trying to accomplish both of these with one method:
    zcl_myclass=>do_something_static( im_key = '1234' ).
    lv_myclass_instance->do_something( ).   " key in private attributes
    Why would I want to do that?
    I would like to avoid instantiation in some cases for performance reasons and would like to keep it simple by having only one method to do basically the same thing.
    Any input or alternative suggestions welcome.
    Cheers,
    Mike

    Ok, I may be reaching here a bit, I know, but maybe this may give you some ideas.  After creating the object, pass it back to the method call.
    report zrich_0001.
    *       CLASS lcl_app DEFINITION
    class lcl_app definition.
      public section.
        data: a_attribute type string.
        class-methods: do_something importing im_str type string
                                   im_ref type ref to lcl_app optional.
    endclass.
    *       CLASS lcl_app IMPLEMENTATION
    class lcl_app implementation.
      method do_something.
        if not im_ref is initial.
           im_ref->a_attribute = im_str.
          write:/ 'Do_Something - ',  im_ref->a_attribute.
        else.
          write:/ 'Do_Something - ',  im_str.
        endif.
      endmethod.
    endclass.
    data: o_app type ref to lcl_app.
    start-of-selection.
      create object o_app.
      call method o_app->do_something(
               exporting
                   im_str = 'Instansiated'
                   im_ref = o_app ).
      call method lcl_app=>do_something(
               exporting
                   im_str = 'Static' ).
    Regards,
    Rich Heilman

  • How do you make a static reference to a method?  I've included code.

    I'm sorry but this is a cross post. This should be here but it is also in the 100% pure Java forum. It won't happen again.
    Now...
    Why doesn't this work? How do I use the method add(int a, int b)?
    ERROR - "Can't make static reference to method int add(int, int) in testClass"
    interface testInterface{   
        static String sString = "TESTING";   
        public int add(int a, int b);
    class testClass implements testInterface{
        public int add(int a, int b){
            return a+b;      
        public static void main(String argv[]){
            int sum = add(3,4);    // here's the error
            System.out.println("test");
            System.out.println( sum );   
    }Again, I apologize for the cross post.

    hi,
    this seems to be pretty easy, isn't it?
    Oh c'mon! You try to invoke a non-static method from within a static method. Solution: Create a specific instance of class testClass:
    testClass test=new testClass();
    test.add(3,4);best regards, Michael

  • How do I make a static reference to a method?  Sample Code Included

    Why doesn't this work? How do I use the method add(int a, int b)?
    ERROR - "Can't make static reference to method int add(int, int) in testClass"
    interface testInterface{
        static String sString = "TESTING";
        int add(int a, int b);
    class testClass implements testInterface{
        public int add(int a, int b){
            return a+b;  
        public static void main(String argv[]){
            int sum = add(3,4);    // here's the error
            System.out.println("test");
            System.out.println( sum );
    }

    Why doesn't this work?Because you can't call a non-static method like add (which operates on the object called this) from a static method like main (for which there is no this).
    There are two ways to fix this:
    (1) In main, create a TestClass object, and call add() for that object:
    class TestClass implements TestInterface {
       public int add(int a, int b) {
          return a+b;
       public static void main(String[] args) {
          TestClass testObject = new TestClass();
          int sum = testObject.add(3, 4);
          System.out.println("test");
          System.out.println(sum);
    }(2) Make add() static. This is the preferred approach, because add() doesn't really need a TestClass object.
    class TestClass implements TestInterface {
       public static int add(int a, int b) {
          return a+b;
       // main is same as the original
    }

  • STATIC REFERENCE

    THE CODE IS ATTACHED. I NEED TO SOLVE THE ERROS.
    THIS IS THE ERRORS AFTER COMPILE
    C:\My Documents\Java\Assignment\Assign3\PwdClient.java:47: Can't make static reference to method void setLayout(java.awt.LayoutManager) in class java.awt.Container.
                        setLayout(new FlowLayout());
                        ^
    C:\My Documents\Java\Assignment\Assign3\PwdClient.java:48: Can't make static reference to method void setBackground(java.awt.Color) in class java.awt.Component.
                        setBackground(Color.green);
                        ^
    C:\My Documents\Java\Assignment\Assign3\PwdClient.java:53: Can't make static reference to method java.awt.Component add(java.awt.Component) in class java.awt.Container.
                        add(l);
                        ^
    C:\My Documents\Java\Assignment\Assign3\PwdClient.java:58: Can't make static reference to method java.awt.Component add(java.awt.Component) in class java.awt.Container.
                        add(name);
                        ^
    C:\My Documents\Java\Assignment\Assign3\PwdClient.java:61: Can't make a static reference to nonstatic variable tf_name in class PwdClient.
                        tf_name = new TextField(20);
                        ^
    5 errors
    //HERE IS THE CODE
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    class PwdClient extends Frame
         private TextField tf_name;
         private TextField tf_password;
         private String input_str_name;
         private String input_str_password;
         private String str_to_pass;
         //private String str;
         //private String str_name;
         //private String str_password;
         //private Button button1;
         private final static int buffsize = 512;
         public static void main(String args[])
              try
                        String server = args[0];
                        int port = Integer.parseInt(args[1]);
                        //create socket
                        Socket s = new Socket(server, port);
                        //readresult from server
                        InputStream is = s.getInputStream();
                        DataInputStream dis = new DataInputStream(is);
                        OutputStream os = s.getOutputStream();
                        DataOutputStream dos = new DataOutputStream(os);
                        InputStreamReader isr = new InputStreamReader(System.in);
                        BufferedReader br = new BufferedReader(isr);
                        //Frame frm = new Frame( "Client Server" );
                        setLayout(new FlowLayout());
                        setBackground(Color.green);
                        String str = "Enter Name and Password:";
                        Label l= new Label( str, Label.CENTER);
                        l.setBackground(Color.red);
                        add(l);
                        String str_name = "Name:";
                        Label name = new Label( str_name, Label.CENTER);
                        name.setBackground(Color.red);
                        add(name);
                        //Name textfield User input for name
                        tf_name = new TextField(20);
                        add(tf_name);
                        String str_password = "Password:";
                        Label password = new Label( str_password, Label.CENTER);
                        password.setBackground(Color.red);
                        add(password);
                        //Password Textfield (user input for password)
                        tf_password = new TextField(20);
                        tf_password.setEchoChar('*');
                        add(tf_password);
                        Button Button1 = new Button("Submit");
                        add(Button1);
                        Button1.addActionListener( new ActionListener()
                             public void actionPerformed(ActionEvent ae)
                                  input_str_name = tf_name.getText();
                                  tf_name.setText(new String(""));
                                  input_str_password = tf_password.getText();
                                  tf_password.setText(new String(""));
                                  str_to_pass = input_str_name+"/"+input_str_password;
                                  dos.writeBytes(str_to_pass);
                                  String received_from_server = brr.readLine();
                                  l.setText(received_from_server, Label.CENTER);
                        frm.setSize( 300, 200 );
                        frm.show();
                        frm.addWindowListener( new WindowAdapter()
                             public void windowClosing(WindowEvent e)
                             { System.exit(0);}
              }//closes the try
              catch(Exception e){}

    Put the code you have in static main in a constructor, or make an instance of PwdClient in main that you can call those methods on. You can't call non-static methods directly from a static method (main). You need to instantiate the class.
    public class PwdClient extends JFrame {
      public PwdClient() {
        // the code from your main method
      public static void main(String[] args) {
        new PwdClient(); // makes a new instance of PwdClient
    }

  • How to make the Reference field in the in Accounting Tab a required field.

    Hi,
    Can i make the REference field in the Accounting tab required. I want to enter contract number from RE in that field.
    Thank you.
    Rachelle

    Hi,
    Goto t.code OVA2 select A-sales header and then click on procedures in the left--> select the procedure in which you want to incolude this field and new entries the table name is VBAK and field is XBLNR for the reference field in the accouting tab and accordingly assign the status 01 or 02 as per your requirement.
    Then you need to assign the incompletion procedure to the sales document type in VOV8.
    Regards,
    Gopal.

  • Error: Cannot make a static reference to the non-static method

    Below is a java code. I attempt to call method1 and method2 and I got this error:
    Cannot make a static reference to the non-static method but If I add the keyword static in front of my method1 and method2 then I would be freely call the methods with no error!
    Anyone has an idea about such error? and I wrote all code in the same one file.
    public class Lab1 {
         public static void main(String[] args) {
              method1(); //error
         public  void method1 ()
         public  void method2 ()
    }

    See the Search Forums at the left of the screen?
    If you had searched with "Cannot make a static reference to the non-static method"
    http://search.sun.com/search/onesearch/index.jsp?qt=Cannot+make+a+static+reference+to+the+non-static+method+&rfsubcat=siteforumid%3Ajava54&col=developer-forums
    you would have the answer. Almost every question you will ask has already been asked and answered.

  • Can i make a method to wait for 2 mins before executing in java??

    can i make a method to wait for 2 mins before executing??
    i mean when i execute a method ....it has to wait for 2 mins before finally executing...
    can i do this in java????
    Thanks,

    Sure, put this at the beginning of the method.
    try
        Thread.sleep(120000);
    catch (Exception ex)

  • Can we override Static methods?

    Hi all, I m in little bit confusion abt static methods overriding.
    Could you help me on this issue.,
    Can we override Static methods?

    You can provide static methods with same name in both super class and subclass. But it is not overriding in this scenario. Both will act as independent methods.
    Example:
    have a super class:
    public class Test1 {
    public static void mthdA()
    System.out.println("in super");
    have a sub class:
    public class Test2 extends Test1{
    public static void mthdA()
    System.out.println("inside sub");
    public static void main(String[] args){
    Test1 objTest = new Test2();
    objTest.mthdA();
    Try to run the sub class Test2. The output would be "in super".
    Remove static modifier in mthdA() in both the classes and then run. The output would be "in sub". Meaning, methdA is overriden in sub class.

  • How can i make reference field mandatory in MIRO?

    Hi Experts,
    How can i make reference field mandatory in MIRO screen.
    Reference field is not available in field status group.
    I have checkedthe reference number in RE document types in OBA7 .
    But still without entering anything in reference field in MIRO,the document is getting save.
    Any other solution??
    Regards,
    Sumeya offrin

    Hi
    Strange....what you did should work.
    Was an accounting document created for this MIRO? Was it RE type?
    Ofer

  • Can we make executable jar file which dont have main method?

    I have a problem.
    With whatever R&D i have done so far my understanding is that in order to create executable jar files i need a main method.
    my problem is i have certain MIS reports which are developed in java and deployed through JSP pages...so my java program has no Main Method and only objects of the classes are being called in the JSP pages.
    for e.g: i have a java class file BulkSms.class and i make an object of it in the JSP page through which my purpose is achieved by calling various method in the BulkSms through it s objects and there is no main method.
    Can i make an executable jar file without a main method and if so please give me a detailed procedure of how to go about it.
    i want to make it executable so tht on the click of it the MIS report is displayed from the JSP page.

    I am completely ignorant of JSPs, but you can not execute a jar or any java application unless you have a main method. It sounds like you need a way to launch the JSP - can't you do this with a browser?

  • When i make calls, all i can hear is static, and when i plug in headphones or turn the speaker on, it still doesnt work. but facetime, music, an apps sound still work. help? iphone 5

    when i make calls, all i can hear is static, and when i plug in headphones or turn the speaker on, it still doesnt work. but facetime, music, an apps sound still work. help? iphone 5

    Hello Delaney1130,
    It sounds like you are getting static on both the receiver and the speaker when you make a call. I would use the troubleshooting from the following article to help resolve the issue named:
    iPhone: Troubleshooting issues making or receiving calls
    https://support.apple.com/kb/TS3406
    Toggle airplane mode: Tap Settings > Enable Airplane Mode, wait five seconds, then turn off airplane mode.
    Check your phone settings:
    Check your Do Not Disturb settings: Tap Settings > Do Not Disturb.
    Check for any blocked phone numbers: Tap Settings > Phone > Blocked.
    See if Call Forwarding is turned on: Tap Settings > Phone > Call Forwarding.
    Ensure that your software is up to date:
    Check for a carrier settings update.
    Check for an iOS software update.
    Note: Some updates may require a Wi-Fi connection.
    If the iPhone has a SIM card, reseat the SIM card.
    If the iPhone 4 or iPhone 4s is on the Verizon network, dial *228 from the iPhone and select option 2 to update the Preferred Roaming List (PRL). The PRL determines the cellular towers the phone uses for cellular service, selecting those with the best signal strength.
    Reset the network settings: Tap Settings > General > Reset > Reset Network Settings.
    Try to make or receive calls in another location.
    Attempt to isolate to one network band:
    If you're having the issue on LTE, disable LTE, if possible, and try again.
    If you're having the issue on 3G/4G, disable 3G/4G, if possible, and try again.
    Contact the carrier to check the following:
    Your account is properly configured to use the specific iPhone that has the issue.
    There are no localized service outages.
    Your account doesn't have a billing-related block.
    Your calls don't have errors on the carrier system.
    Restore the phone as new.
    If the above steps don't resolve the issue, go to an Apple Retail Store, carrier, Apple Authorized Reseller, or contact AppleCare to send the phone in for service.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Can I make a static screen saver for an LCD screen?

    Can I make a static screen saver for an LCD screen? In researching screensavers the other day, I read an article saying that moving images were no longer necessary since that was important for cathode monitors and LEDs have no such problems but the iMacs are LCD. Do LCD get "Burn in"?
    I need to know as I am making wallpaper and screensvers for the company I work at.

    LCD's normally are not affected by any burn in, just use the computer. It's a wise idea to put the display to sleep when it's not in use.  You can set the setting in System Preferences - Energy Saver. I set my display to sleep after 15 minutes of not being used and it goes black, I've done this for 8+ years and have never had any display issues.

Maybe you are looking for

  • [solved] Video conversion problem: Mencoder on Arch versus Windows XP

    I have a cheap portable video player which (according to a supplied Windows software configuration file) requires any video to be converted (say from a YouTube .flv) using a command line like: mencoder myfile.flv -ofps 15 -vf-add scale=160:128 -vf-ad

  • Design a sheduler, like in outlook express

    hi I want to design a sheduler like we have in outlook Express, can some one guide???? Is there any website describing to design a one in details

  • JDeveloper 10g on Oracle 9iDB

    1. Can I use JDeveloper 10g on 9i DB? 2. Can I install SRDEMO schema for the tutorial on 9i DB? Thank you in advance. Jimmy

  • Laserjet M475DW won't print last page from iPad

    It's all in the subject. The printer prints fine via the iPad PrinterControl app but won't print the last page of the Word document or Powerpoint slide deck. Since you can't choose which page to print from PrinterControl, I can't force the printer to

  • ***UDF for Splitby Value

    Hi all, My requirements is not to use Split by value.I require a UDF code for the same. Thanks, Srinivasa