Results 1 to 3 of 3
  1. #1
    hendrix79 is offline Member
    Join Date
    Dec 2008
    Posts
    28
    Rep Power
    0

    Default [SOLVED]Usual problem: cannot make a static....

    Hello friends. Please, help me with this.

    I simply need a login page. I created a button that will call patterns.Controlli.ConfermaLogin(campo_nome_utente , campo_password);

    and Eclipse IDE returns me a Cannot make a static reference to the non-static method ConfermaLogin(JTextField,
    JPasswordField) from the type Controlli

    Here's my code:

    Login.java
    Java Code:
    private void tasto_confermaActionPerformed(ActionEvent evt) {
    		System.out.println("registra.actionPerformed, event="+evt);
    	    patterns.Controlli.ConfermaLogin(campo_nome_utente, campo_password); 
    	}
    Here's patterns.Controlli.java

    Java Code:
    public void ConfermaLogin(JTextField nome_utente, JPasswordField campo_password){
    			
    			String testo_nome = nome_utente.getText();
    			String testo_password = "";
    			char[] char_pass = campo_password.getPassword();
    			testo_password = String.valueOf(char_pass);
    			if (testo_nome.equals("") || (testo_password.equals(""))) {
    			JOptionPane.showMessageDialog(null, "Bisogna inserire nome utente e password.", "Non hai inserito tutti i campi!", JOptionPane.WARNING_MESSAGE);
    			} 
    				else
    					{
    						JOptionPane.showMessageDialog(null, "Ok.", "Campi inseriti!", JOptionPane.WARNING_MESSAGE );
    						GestInterfaccia.Accesso(testo_nome, testo_password);
    						
    					}
    		}
    and up above, this command

    Java Code:
    GestInterfaccia.Accesso(testo_nome, testo_password);
    return this error:

    Cannot make a static reference to the non-static method Accesso(String, String) from the
    type GestInterfaccia.

    Here's GestInterfaccia.java
    Java Code:
    public void Accesso(String campo_nome, String campo_password) {
    		
    		patterns.BusinessDelegate.accesso(campo_nome, campo_password);
    		
    	}
    and returns me this error:
    Cannot make a static reference to the non-static method accesso(String, String) from the
    type BusinessDelegate

    and here's BusinessDelegate.java
    Java Code:
    public class BusinessDelegate {
    
    	public void accesso(String campo_nome, String campo_password) {
    	
    		database.GestoreQuery.accesso(campo_nome, campo_password);
    		
    	}
    	
    	
    }
    I really can't understand how i can handle static and non-static. I know what does it mean, but i can't make it work.
    Somebody help me!
    Sorry for the intrication, but... that's how i need, it's not a small program, so i need to make some calls.
    Please make some examples with my code, so i can understand better, and finally i won't break you anymore :P
    Last edited by hendrix79; 12-15-2008 at 03:20 PM. Reason: Solved, thanks alot.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Java Code:
    class SomeClass{}
    
    class anotherClass
    {
       SomeClass sc = new SomeClass();
       sc.doSomething();
    }
    I left out some bare essentials to focus on your central challenge....In short, we have to "declare an instance of a class" which is what the SomeClass sc = new SomeClass(); does, we then place the method names of that class directly up against the name of the class followed by a dot '.' - this occurs in another class, that is called an instance of that class.

    The keyword static works without calling new, but it has to be everywhere one uses the class from a static context....

    if not this help, ask further.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    hendrix79 is offline Member
    Join Date
    Dec 2008
    Posts
    28
    Rep Power
    0

Similar Threads

  1. Static Vector Problem
    By calicocal in forum New To Java
    Replies: 12
    Last Post: 11-09-2008, 11:31 PM
  2. Please help, need to make my class static.
    By sumak in forum New To Java
    Replies: 1
    Last Post: 04-19-2008, 07:29 AM
  3. Replies: 0
    Last Post: 04-16-2008, 11:07 PM
  4. Replies: 1
    Last Post: 08-07-2007, 05:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 09:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •