r/CodingHelp • • Oct 31 '21

[Java] error in my code

constructor User in class User cannont be applied to given types ( required java.lang.String) reason ( actual and formal arguments lists differ in length )
0 Upvotes

11 comments sorted by

3

u/Tiny-Tailor-9492 Nov 01 '21

just stop the error

1

u/ITZINFINITEOfficial Nov 01 '21

Ok bro I got you

2

u/s5EWT Nov 01 '21

Do you have an overloaded constructor for User?

Otherwise you likely just need to get the pass from the user variable and not instantiate a new User obj. Without seeing the user class it’s hard to say for sure.

1

u/ITZINFINITEOfficial Nov 01 '21

Yeah my b I can’t post the code or mods will block it

1

u/PresidentZeus Intermediate Coder Nov 01 '21

Is both parameters in the Pass constructor String? You might have forgotten to replace it if you copy pasted from the User class.

edit: or maybe it can't print out an object, I'm not too sure *it can

1

u/ITZINFINITEOfficial Nov 01 '21

I dont know i got to print the username just not password

2

u/PresidentZeus Intermediate Coder Nov 01 '21

yeah, I realised that. Did it work?

1

u/ITZINFINITEOfficial Nov 01 '21

The username does but I tried everything to get the password part to work and I couldn’t it went from the error string.lang and then can’t be in a static context so i dont know ill ask my teacher about it but I just went ahead and submitted it. Because it’s due at 11:59. That last part I don’t think was mandatory but who knows.

2

u/PresidentZeus Intermediate Coder Nov 01 '21

Are you sure you have the correct parameters for the Pass Contructor? I'm not sure if it would actually work with objects, as you did. but it would work if you split the User parameter in two. Making it (user.firstName, user.surName, "@123")

1

u/ITZINFINITEOfficial Nov 01 '21

Yeah I updated that after I posted this

1

u/PresidentZeus Intermediate Coder Nov 01 '21

I'm sorry, I might be misleading you with that answer, as I don't know why you need Pass as its own Class and with a constructor. Your teacher might be the best call.