简体   繁体   中英

“java.lang.NullPointerException: Attempt to write to null array” for int[][] var = new int[m][n]

I'm getting this weird exception report from other users:

java.lang.NullPointerException: Attempt to write to null array
    at yuku.alkitab.base.util.Levenshtein.distance(Levenshtein.java:16)

The relevant snippet is:

private static final int deletion = 500;

public static int distance(String s, String t) {
    // d is a table with m+1 rows and n+1 columns
    int m = s.length();
    int n = t.length();

    int[][] d = new int[m + 1][n + 1];

    for (int i = 0; i <= m; i++) {
        d[i][0] = i * deletion; // <------ this is line 16
    }

    // more lines omitted
}

Examining the above code I could not find out how that exception can ever happened. Did I miss something?

All crash reports came from Android 6.0, API 23.

Please provide more information to the question. Currently the only thing that should make the code not work, is that it is not returning the value it should return (int).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question java.lang.NullPointerException: Attempt to write to field 'int android.support.v7.widget.RecyclerView java.lang.NullPointerException: Attempt to invoke virtual method FloatingActionButton.setImageResource(int)' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'ActionBar.setNavigationMode(int)' on a null object reference Android java.lang.NullPointerException: Attempt to get length of null array java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference from server to spinner java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[])' on a null object reference Error: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View .MainActivity.findViewById(int)' on a null object reference java.lang.NullPointerException: Attempt to invoke interface method 'int android.database.Cursor.getCount()' on a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM