Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am getting both these errors (on the marked line) with the following code in java;
String data[] = file.getInput();
while(data[0] != "X"){
String ID = data[0];
String firstName = data[1];
String lastName = data[2];
data[] = file.getInput(); //errors occurr here
}
Note that file.getInput() is a method that returns an array of Strings from a CSV file using the InputReader.
Just remove the [] from data.
data = file.getInput();
Remove the ‘[]’ from data :
data = file.getInput(); ‘Do the statement like this’
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I made following code for Gender field in a form and i can't find my error. Any help is appreciated
Gender =
if (male.isSelected()) Gender="Male";
else if(female.isSelected()) Gender="Female";
I am new to NetBeans and this Site. So Please Help Me
I get the error in if statement
You should not initialize String with if instead use :
String gender = "";
if (male.isSelected()) {
gender = "Male";
} else if (female.isSelected()) {
gender = "Female";
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'mm working on this program in which connects Prolog and Java GUI. And i am encountering this problem where i don't know how many solutions the prolog program is gonna pass to java and therefore i can't declare the String array with fixed-length. This is my code:
String[] options; int i;
Query qMeat = new Query(new Compound("meat", new Term[] {new Variable("X")}));
i = 0;
while(qMeat.hasMoreSolution()){
options[i] = "" + qMeat.nextSolution().get("X");
i++;
}
I am getting this NullPointerException, which i guess because i didn't initialize the String array to null. And i don't know how to do so. I tried java.util.Arrays.fill(options,"") But not helping =(
Please help.
If you don't know the required size of the array in advance, you should use an ArrayList instead.
List<String> options = new ArrayList<>();
while(qMeat.hasMoreSolution()){
options.add("" + qMeat.nextSolution().get("X"));
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
String x = "5+7";
String []n = x.split("\\+");
System.out.println(n[0]); // =5
System.out.println(n[1]); // =\
Your code should work fine, but I'd try to make it more robust:
String test = "5 + 7";
String[] tokens = test.split("\\s*\\+\\s*");
for (String token : tokens) {
System.out.println(token);
}
The \\s* will allow for possible white-space between the numbers and the + char.
use
x.split("[+]");
That will split it correctly.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi I have some string.
String cos = "Something I do not know ThisIWantToFind Something I do not know";
And how I can find this with regex ?
I tried with:
result = cos.matches("(.*)ThisIWantToFind(.*)");
and
result = cos.matches("(.*?)ThisIWantToFind(.*?)");
but this not work :(
without regex
case sensitive
String cos = "Something I do not know ThisIWantToFind Something I do not know";
if (cos.indexOf("ThisIWantToFind") > -1)
{
// found
}
not case sensitive
String cos = "Something I do not know ThisIWantToFind Something I do not know";
if (cos.toUpperCase().indexOf("ThisIWantToFind".toUpperCase()) > -1)
{
// found
}
You want to know if the regex is in the string or the position of the regex in the string?
for the first one, I guess this should work ..
boolean result = cos.matches(".*ThisIWantToFind.*");
?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I guess its a rather simple question but i just cant find my mistake.
int[] myIntArray = new int[20];
myIntArray[5] = 5;
int a = myIntArray[5];
TextIO.putf("arr[i]: d%",a );
The error I get is Illegal format string in TextIO.putf() method.
So I assume the value at the index 5 is not an int?
The error message says exactly what the problem is: your format string is wrong. You probably meant %d (or better yet, %d%n to add a newline).
The format string elements are in the form
%[modifiers]type
not
something%
Change d% to %d.