Coding issue

Status
This thread has been locked.

EnchantBook

Premium
Feedback score
13
Posts
705
Reactions
108
Resources
0
private boolean isInt(String string) {
try {
Integer.parseInt(string);
return true;
} catch(NumberFormatException nfe) {
return false;
}

}
if(material == null || !isInt(rawAmount)){
player.sendMessage(ChatColor.RED + "Invalid use!");
player.sendMessage(ChatColor.RED + rawAmount);
player.sendMessage(isInt(rawMaterial) + "");
return true;
}
For some reason this returns a false even if It's an integer
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Bill

a rare billy boy has appeared
Premium
Feedback score
11
Posts
842
Reactions
336
Resources
0
On a quick glance I believe your code should work.

I know this works, but it is the same thing basically.
Code:
try{
int i = Integer.parseInt(args[0]);
//Whatever
}catch(Exception e) {
//Exception
}

Not sure what the issue is exactly, might be with the checks.

You could try changing it to any of these.

Code:
if(isInt(rawAmount) == false) {}
if(!(isInt(rawAmount))) {}
if(isInt(rawAmount) != true) {}
if(isInt(raw)){}else{//whatever}
 

EnchantBook

Premium
Feedback score
13
Posts
705
Reactions
108
Resources
0
On a quick glance I believe your code should work.

I know this works, but it is the same thing basically.
Code:
try{
int i = Integer.parseInt(args[0]);
//Whatever
}catch(Exception e) {
//Exception
}

Not sure what the issue is exactly, might be with the checks.

You could try changing it to any of these.

Code:
if(isInt(rawAmount) == false) {}
if(!(isInt(rawAmount))) {}
if(isInt(rawAmount) != true) {}
if(isInt(raw)){}else{//whatever}
My code is working for a friend but not for me, can't find the reason why though[DOUBLEPOST=1533776024][/DOUBLEPOST]
StringUtils#isNumeric Checks if a CharSequence contains only Unicode digits. You will just have to remove "!isInt(rawAmount)" and put "!StringUtils.isNumeric(rawAmount)"
https://gyazo.com/e78f64678c9dde6716994c82a2aed1c3?token=129c2f55b5e7894b3cf208f399c35b09
 

WulfGamesYT

( ͡° ͜ʖ ͡°)
Supreme
Feedback score
17
Posts
172
Reactions
159
Resources
0
Try the following:

Code:
public boolean isNumeric(Object object) { return object.toString().matches("^[0-9]\\d*$"); }

then simply use:

Code:
if(!isNumeric(54)) { /* not a number */ }
 

EnchantBook

Premium
Feedback score
13
Posts
705
Reactions
108
Resources
0
That's true, but I use the same method and haven't had any issues with it.
However, there could be an issue with whatever he's inputting into it.
Such as "24 " is not an Integer
Sent the code to a friend and it worked fine for him, something with the compiling most likely, Thanks though
 
Status
This thread has been locked.
Top