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 3 of 3

Thread: Java land null point exception

  1. #1
    Junior Member
    Join Date
    Jun 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java land null point exception

    Hello,

    I am a beginner of java. I wrote this code. When I run it in eclipse, I get an error: java lang null point exception. It does not tell me which line I have wrong code. Please advise on how to fix it.

                int  TotalCol;
                int  TotalRow;
     
                TotalCol = 0;
                TotalRow = sheet.getLastRowNum();
                TotalCol = sheet.getRow(0).getLastCellNum();
       	        System.out.println("row " + TotalRow +  " col " +  TotalCol);
     
                int resultcol = 0;
    	    	for(int col = 0;col<=TotalCol;col++){
     
    	    	     HSSFRow row1 = sheet.getRow(0);
    	    	     System.out.println("column names " + row1.getCell(col).toString() );
    	    	 	if("result".equalsIgnoreCase(row1.getCell(col).toString().trim()))
    				{
    	    	 		resultcol = col;
    		    	     System.out.println("result column number " + resultcol );
     
    				}
     
    	    	}
    Last edited by Norm; June 21st, 2017 at 04:51 PM. Reason: HTML tags changed to code

  2. #2
    Member
    Join Date
    May 2017
    Location
    Eastern Florida
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Java land null point exception

    I get an error: java lang null point exception
    Please copy the full text of the error message and paste it here. It has important info about the error that is needed to fix it.

    Please wrap your code in code tags, not html tags.

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Java land null point exception

    As Norm pointed out we really need the full error log. But at a quick glance, your for loop should probably only have a < symbol, not <=. It's probably causing your to try and retrieve a non existent cell which you are calling toString on.

Similar Threads

  1. null pointer exception, please help!
    By tkocher13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 11th, 2014, 10:11 AM
  2. Need Help with Null Pointer Exception
    By kendraheartt in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 23rd, 2012, 02:20 PM
  3. [B]Null Pointer Exception[/B]-- Please Help!!!
    By entwicklerin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 24th, 2012, 11:24 AM
  4. Java Null Pointer Exception
    By destructobob in forum Exceptions
    Replies: 5
    Last Post: December 9th, 2011, 12:53 PM
  5. Null Pointer Exception
    By MysticDeath in forum Exceptions
    Replies: 2
    Last Post: October 24th, 2009, 01:49 PM