Charlie
Charlie

Reputation: 1338

How to call this instance method

Hi I am trying to call a non-static method with a return type of boolean,

if there was a static in there I would know how to do it, but the static seems to throw it all away, I have tried to create a new instance of the method with the line

    Loginn auth = new Loginn(1,2,3)

and also

   Login.Loginn auth = new Login.Loginn(1,2,3)

The code can be found here...

http://www.pastebin.com/qwAtR7u0/

thanks

c

Upvotes: 0

Views: 211

Answers (7)

user800014
user800014

Reputation:

In your code Loginn is a public method, not static. So you need to call like:

Login login = new Login();
login.Loginn("user","pass","ip");

If you transform the method to static (public static Loginn) then you can use:

Login.Loginn

Also, take a look at the java code conventions for better naming your methods.

Upvotes: 0

Alan Escreet
Alan Escreet

Reputation: 3549

You aren't calling a method at all! You're calling a constructor.

It's called like this:

Loginn auth = new Loginn("username", "password", "IP");

You can't call it with integers - the 3 parameters are Strings.

Upvotes: 0

Hot Licks
Hot Licks

Reputation: 47729

To call a static method you code result = ClassName.methodName(parameters);

(But I can't, at first glance, see any static methods in the code you referenced.)

Loginn you'd call as:

Login instance = new Login();
boolean result = instance.Loginn(parameters);

Or you could do:

boolean result = new Login().Loginn(parameters);

Upvotes: 1

Habib
Habib

Reputation: 223287

if its a static method with return type of Boolean then try :

if(Login.Loginn(1,2,3))
{
//your code here
}
else
{
//some code
}

Or

boolean result = Login.Loginn(1,2,3);

Upvotes: 1

Ryan Nelson
Ryan Nelson

Reputation: 4676

There isn't a static method in that code you posted.

public class Login {
    ...

    public boolean Loginn(String UserName, String PassWord, String IP) throws UnknownHostException, IOException { ... }
}

To invoke that method, you simply call the method name on the object instance:

Login myLogin = new Login();
myLogin.Loginn( username, password, IP);

Upvotes: 1

usethe4ce
usethe4ce

Reputation: 23819

Based on what's there, you seem to want:

Login login = new Login();
login.Loginn(1,2,3);

Upvotes: 0

aglassman
aglassman

Reputation: 2653

You call static methods like so:

Login.Loginn(1,2,3)

You don't need the new keyword.

Also, you probably don't want to assign anything to Login.Loginn whatever that may be...

Upvotes: 1

Related Questions