S
S
Sergey Kuznetsov2015-05-28 04:16:31
Java
Sergey Kuznetsov, 2015-05-28 04:16:31

Why is the variable not being assigned?

I understand that it's a noob question, but I still couldn't figure it out because there's not enough time.
Why when passing a variable in this way, the variable takes the value of Null.
When I output this variable in this class, it outputs Null.
Explain if not difficult.
3b6be7fd37a4413cac35044b68f19c8b.PNG

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
protven, 2015-05-28
@protven

Probably because you're passing null to the method, aren't you?
Add
System.out.println(LOGIN == null);
to your code.
And read the java code convention, your class, method and variable names are just awful.

U
urmi tilek uulu, 2015-05-28
@urma

And how do you call your USER_NAME_AGREEMENT(String LOGIN) method?
Try running this class:

public class Test{
   public static String userName;

   public static void main(String args[]){
         userNameAgreement("test login");
   }

   public static void userNameAgreement(String login){
        userName = login;
        System.out.println("Agreement: " + userName);
   }
}

Yes, and everything should work for you.
Maybe you are passing null or not calling your USER_NAME_AGREEMENT(String LOGIN) method.
Of course it's up to you how you write your code, but I would join protven . Usually in java, in capital letters, using the example of your public String USER_NAME, they write static variables, etc. and methods are lowercase.

A
Anhedonia, 2015-05-28
@Anhedonia

Check for null at the beginning of the method and you will be happy
. There will be something like

public String USER_NAME;
    public void USER_NAME_AGREEMENT(String LOGIN) {
    	if (LOGIN == null) throw new IllegalArgumentException();
    	USER_NAME = LOGIN;
    	System.out.println("Agreement: " + USER_NAME);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question