Search code examples
javaintellij-ideabufferedreaderjsmooth

Java - NoSuchMethodError on java.io.BufferdReader.lines on other systems


I'm using a small "xml text based database" to store information. While coding and debugging I had no problems with a method I created, but as an exe file(wrapped with jsmooth), it gives me an error:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: java.io.BufferedReader.lines()LJava/util/stream/Stream: 
      at primary.loadErrorDB(primary.java:471

So i checked line 471 but on Intellij, there is no such error, everything works fine there.

Hope you guys know what to do.

This is the method

    public static Object[] loadErrorDB() {

    File db = new File(System.getProperty("user.dir") + "\\errordb.xml");

    Object[] errordbAry = new String[20][20];

    FileReader file = null;
    try {
        file = new FileReader(db);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        BufferedReader br = new BufferedReader(file);

        Stream<String> streamList = br.lines();

        errordbAry = streamList.toArray();

    } catch (Exception ex) {
        ex.printStackTrace();
    }


    String a = "";
    for (Object o : errordbAry) {
        a = a + String.valueOf(o) + ";";
    }

    String[] srgAry = a.split(";");

    String[] newAry = new String[srgAry.length - 5];
    int x = 0;

    for (int i = 5; i < srgAry.length; i++) {
        newAry[x] = srgAry[i];
        x++;
    }

    return newAry;

}

Solution

  • br.lines(); <--BufferedReader don't have method lines() upto Java7 use readLine()
    

    Update Java to Java8 to use this feature.

    If You want to read one line at a time use

    String line=br.readLine();
    

    Before that make sure that file you are trying to read has line by null check.

    String line=null;
    if((line=br.readLine())!=null)
      {//Go Ahead
      }
    

    See more one this from BufferedReader