Insert != null check issues
I am making something that turns a string into an Integer if it is an Integer, or keeps it as a String if it is a String. I have that bit working fine, it is just when I try and check to see what the String is (if it is a string) I get Eclipse saying I have to insert != null because I am converting a boolean into a string. The thing is, if I click on it, it just makes more errors.
Here is my code:
Code :
import java.io.*;
public class gplReader {
//Class variables
files f = new files();
//General Variables
boolean nextIsInt;
public gplReader(){
}
public void startRead(String name) throws IOException{
try{
System.out.println("Reading File");
String[] aryLines = f.readFileData("gpl/" + name);
System.out.println("Reading Data");
int i;
for(i=0; i<aryLines.length; i++){
System.out.println("Printing line" + " " + (i+1) + " ");
System.out.println(aryLines[i]);
System.out.println("Interpreting line" + " " + (i+1) + "");
interpretGpl(aryLines[i]);
}
} finally {
System.out.println("\nFinished Printing Lines\n");
}
}
public void interpretGpl(String aryLines){
String line = aryLines;
String[] tempString = null;
int[] tempInt = null;
int i = 0;
boolean isInt;
boolean storeValue = false;
try{
Integer.parseInt(line);
System.out.println("Line is Integer" + "\n");
isInt = true;
if(isInt != false){
tempInt[i] = Integer.parseInt(line);
}
} catch (Exception ex){
System.out.println("Line isn't an Integer" + "\n");
isInt = false;
if(isInt != true){
tempString[i] = line;
}
}
if(isInt != true){
if(tempString[i] != null){
----if(tempString[0] = "printf"){----
}
}
}
}
}
The line of code surrounded by ---- is the bit that is throwing up errors.
Hope you can help.
Re: Insert != null check issues
Hello JamEngulfer221!
Code java:
if(tempString[0] = "printf")
The above statement is an assignment; you assign "printf" to tempString[0]. I think that instead of this assignment you want to compare them. Therefore you need to use the String's equals() method (instead of the == operator), since they are Strings.
Hope it helps.
Re: Insert != null check issues
No... No... There's no way I could have done that... Wow. I can't believe the absolute stupidity of what I did. I just can't believe it. Well, great. Thanks for the help though!
Re: Insert != null check issues
Don't feel that way, evereybody is making that kind of errors at times.
And something else I noticed.
You should initialize an array before you try to assign a value to an index of it otherwise a NullPointerException will be thrown.