Results 1 to 6 of 6
  1. #1
    Stephenmak is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default Null pointer exception

    Hi all,

    I'm confused with the runtime NullPointerException occured at the arrow line of the following code segment.

    BufferedReader in;
    String line;
    StringBuffer sb = new StringBuffer();
    sb=null;
    byte[] result;
    try {
    FileReader fileReader = new FileReader(this.filename);
    System.out.println("filename is "+this.filename);
    in = new BufferedReader(fileReader);

    do{line=in.readLine();
    if (line != null){
    --> sb.append(in.readLine());}
    }while (line != null);
    String str=new String(sb.toString());
    result = mac.doFinal(str.getBytes());
    System.out.println(filename+" :"+result);
    }

    Please help!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    28

    Default

    The compiler never lies:

    Java Code:
    sb=null;
    construct your StringBuilder before using it, and you should have no problems.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    11

    Default

    I'm sorry, but ROFL
    Java Code:
    StringBuffer sb = new StringBuffer();
    sb=null;
    ...
    sb.append(in.readLine());}
    What did you expect?

  4. #4
    kbindumadhavi is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Rep Power
    0

    Default

    Comment following line:
    sb=null;

  5. #5
    amt_asc is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    Hi Folks,

    I just joined this Forum ...I am stuck up with a problem related with 2 phase commit in case of Distributed transactions...I have decided to go for JBoss JTA for achieving that..but I am getting two errors XA error -4 and SQL exception 24756...can somebody help me on this ...

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    10

    Default

    amt asc... it is not considered good taste to post on somebody else's post (it's called hijacking). Please start your own post, make sure you're in the correct sub-forum and list all errors (complete stack dumps) along with associated code.

    Luck,
    CJSL
    Last edited by CJSLMAN; 04-01-2009 at 02:26 PM. Reason: typo
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 06:48 PM
  2. Null Pointer Exception
    By andre1011 in forum Advanced Java
    Replies: 4
    Last Post: 02-07-2009, 04:30 AM
  3. Null Pointer Exception
    By ScKaSx in forum New To Java
    Replies: 1
    Last Post: 01-24-2009, 12:27 PM
  4. Null Pointer Exception
    By Jacinth in forum New To Java
    Replies: 4
    Last Post: 01-22-2009, 02:47 PM
  5. getting a null pointer exception
    By Rjava in forum XML
    Replies: 4
    Last Post: 07-16-2008, 05:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •