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

Thread: Getting Exception Errors, But Not Sure How To Fix Code

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting Exception Errors, But Not Sure How To Fix Code

    Never mind, I figured out what I had to do
    Last edited by noel222; February 1st, 2012 at 07:12 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Getting Exception Errors, But Not Sure How To Fix Code

    but I am getting exception errors,
    What errors? Post them in their entirety

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting Exception Errors, But Not Sure How To Fix Code

    The error is

    Exception in thread "main" java.lang.NullPointerException

    I am not really sure what is wrong, and have been trying for a very long time to get this code working, but can't seem to.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Getting Exception Errors, But Not Sure How To Fix Code

    Quote Originally Posted by noel222 View Post
    The error is

    Exception in thread "main" java.lang.NullPointerException

    I am not really sure what is wrong, and have been trying for a very long time to get this code working, but can't seem to.
    That is not the full exception - it should contain line numbers which tell you exactly where the exception is being thrown. Even then, we cannot match those line numbers up to your code given they are just small snippets (why we typically ask for an SSCCE). Find that line number and determine what is null - using System.out.println to print objects would be a first place to start to determine what is null and then backtrack to findthe cause.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Getting Exception Errors, But Not Sure How To Fix Code

    This issue is with calling the method on object whose value is null.

    so make sure you write a one condition (if obj!=null) before calling a method to avoid the exceptions. This is always good idea to check for validating object

Similar Threads

  1. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  2. Need Help Writing Exception code.
    By USCPaddler in forum Exceptions
    Replies: 4
    Last Post: November 10th, 2011, 06:45 PM
  3. I still have errors. Can you PLEASE correct my code?!
    By sam30317 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 6th, 2011, 06:10 AM
  4. Please check the code for the errors
    By nrao in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 16th, 2010, 05:37 PM
  5. Exception Errors
    By TIMBERings in forum Exceptions
    Replies: 1
    Last Post: December 10th, 2009, 02:13 AM