Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Insert != null check issues

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    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.


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Insert != null check issues

    Hello JamEngulfer221!
    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.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!

  4. #4
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default 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.

Similar Threads

  1. how to check null
    By veens in forum JDBC & Databases
    Replies: 7
    Last Post: November 16th, 2011, 06:54 PM
  2. string==null or string.equals(null) problem
    By csharp100 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: November 4th, 2011, 09:17 AM
  3. how to insert the value to table in form
    By palani in forum AWT / Java Swing
    Replies: 4
    Last Post: September 3rd, 2010, 01:23 PM
  4. Unable to insert records
    By javaprogrammer11 in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 24th, 2010, 04:16 AM
  5. Insert sort algorithm
    By Alysosh in forum Algorithms & Recursion
    Replies: 1
    Last Post: May 26th, 2009, 10:28 AM