Not Working

52 AM
this code is not working

Keep in mind that “not working” doesn’t explain what’s happening, because it involves already knowing what you mean

Make it abundantly clear what’s happening and what’s stopping you from resolving it yourself. Ask questions.

1 Like

what is wrong with the str.split("") am I doing anything wrong the error says that the parentheses are the cause of the error

Error messages do more than just point. You gotta read them. error: incompatible types: String[] cannot be converted to String

As you can tell from the error message, you were trying to treat a string array like a string.

You’ll get a similar error message if you try to assign a string to an int variable:

error: incompatible types: String cannot be converted to int
        int blah = "hello";

With that information you can consider whether you intended to get a string as a result (in that case you’ll have to use some other method or do additional steps first) or if you simply gave your variable the wrong type.

Generally when asking something, help others understand the situation so that they’re able to figure out what information you’re missing. Otherwise it’s a guessing game. People are willing to help, but they’re usually not willing to also first guess what help is needed because that’s many times more effort, most of it wasted.

1 Like

Sorry but I am new to java so how do I fix it

You fix things by understanding them. Every single part. When there’s a problem you gotta consider the situation and reason out what you need to change to get your desired outcome.

So you start by reading the error message, which says there’s a type mismatch. It tells you where. You then have to go to that location and ask yourself what you meant to happen there, and then read the code to find where something is different from that. If you can’t find it that way, then it means you don’t know how to do that thing in the first place – the solution to that is to find out how to do the thing you meant to do. Again, you’ll need to stop and think about what information you’re missing, and then you can use a search engine (somebody else probably asked the same thing) or describe the situation along with what information you’re missing.

If your question is “not working” and “how do I fix it” then you’re asking someone to write your code for you, you’ll only get as far as to the next bug, and then you’ll have to ask again. As far as you’ve let others know, you haven’t even considered the problem.

If this still doesn’t tell you how to proceed, then you should probably just practice with simpler code. Use components that you understand, combine them, add new knowledge to it. Don’t skip ahead and expect others to fix it for you, it’s not good for anyone.

I won’t guess what you want to know, and I won’t enable you to move forwards without having having finished what you’re currently doing. What you show that you need to learn is how to ask questions and how to address problems. So here I am answering that instead of what answer you’re expecting to get out of this.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.