Results 1 to 2 of 2
  1. #1
    shilpa80 is offline Member
    Join Date
    Mar 2014
    Rep Power

    Default Exception in thread "main" java.lang.NullPointerException

    Iam new to this forum and trying to write a code to remove comment lines from the input java file.Iam getting an error -Exception in thread "main" java.lang.NullPointerException. Please tell me whats wrong in the code.It is showing error- Exception in thread "main" java.lang.NullPointerException in- return new String(buffer),, and the word "String" everywhere present in the program.....Please help me out.

    public static void main(String[] args) {String source = readFile("");

    System.out.println(source.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)| (?://.*)",""));


    static String readFile(String fileName) {

    File file = new File(fileName);

    char[] buffer = null;

    try {
    BufferedReader bufferedReader = new BufferedReader( new FileReader(file));

    buffer = new char[(int)file.length()];

    int i = 0;
    int c =;

    while (c != -1) {
    buffer[i++] = (char)c;
    c =;

    } catch (IOException e) {

    return new String(buffer);

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Exception in thread "main" java.lang.NullPointerException

    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: 04-19-2012, 08:10 PM
  2. Replies: 5
    Last Post: 12-21-2011, 07:44 PM
  3. Replies: 5
    Last Post: 10-11-2011, 01:16 AM
  4. Replies: 6
    Last Post: 07-16-2009, 04:30 PM
  5. Replies: 1
    Last Post: 07-16-2009, 11:35 AM

Tags for this Thread

Posting Permissions

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