if (type == "REGISTRATION"){
String name = json.getString("name");
String Location = json.getString("loc");
Client.Registration(username, password, name, Location); //error
DatabaseController.registerUser(Pobj, userObj);
}
Client.java
public static boolean Registration(String username, String password, String name, String loc){
clientUsername = username;
clientPassword = password;
clientname = name;
clientlocation = loc;
}
Registration function is defined here it gives me error like:
method Registration(String, String, String, String) is undefined for the type Client
In java (and many other programming languages), your methods (or functions) have to have a return type . In your case, you declared the return type of your function to be boolean
. This however means that this method must return a boolean . In your code, you have no return statement.
To solve the problem: you could either add a return statement, or change the return type to void
, meaning it doesn't return anything.
Considering that you aren't returning anything in your function, I suggest using the second option, as follows:
public static void Registration(String username, String password, String name, String loc)
{ ... }
Also, as @Peadar Ó Duinnín mentioned, Java methods should be written in camel case, meaning the first word is not capitalized, but all the words after are, ie myFunctionThatDoesSomething()
. This means your method should become registration(...)
Your Registration
method (which should be registration
. Method/Functions are camelCase in Java.) should be in your Client class as follows. You should also be returning a boolean or change the method signature to public static void registration(...
public class Client {
public static boolean registration(String username, String password, String name, String loc) {
clientUsername = username;
clientPassword = password;
clientName = name;
clientLocation = loc;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.