Solved Unknow NullPointerException

Discussion in 'Plugin Development' started by 0verFull, Jun 25, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    0verFull

    Hi, I need your help with my plugin.

    I have
    Code:
    String[][] strs = new String[][]{new String[]{...},....};
    System.out.println(strs);  //print the object, not null
    for(int i = 0; i < strs.length; i++)
        System.out.println(strs[i]);  //print the object, not null
    
    Data data = DataUtils.read(strs)  //NullPointerException, strs is null, I don't understand why
    My mind is completely confused, I tried a lot of things and I can't see why strs is null.

    Can you help me?

    Thanks!
     
  2. Online

    timtower Administrator Administrator Moderator

    @0verFull What are you trying to do? Why do you need a nested array of strings?
     
  3. Offline

    0verFull

    @timtower It's the needed parameter of the method DataUtils#read(String[][])

    I use this in another plugin and it works but here, I don't know why it's null in read() method while it's not null the line before (nothing change...)
     
  4. Online

    timtower Administrator Administrator Moderator

    @0verFull You sure that it isn't in the DataUtils then?
     
  5. Offline

    0verFull

    @timtower
    I'm sure DataUtils is an own created class and read() method start with

    public static Data read(String[][] strs) {
    if(strs == null)
    // throw NPE

    ....
    }
     
  6. Online

    timtower Administrator Administrator Moderator

    @0verFull strs won't just become null though.
    Where does DataUtils come from?
     
  7. Offline

    0verFull

    @timtower It comes from an own created API. So in the plugin I'm writing, it's considered like an external source.
     
  8. Online

    timtower Administrator Administrator Moderator

    Then look at the source of the API, find the nullpointer.
     
  9. Offline

    0verFull

    @timtower the API is mine. Read() method is in the API
     
  10. Online

    timtower Administrator Administrator Moderator

    Then post the code for your method in this plugin, code for that function, and the error.
     
  11. Offline

    Strahan

    .... then in this question:
    You should have answered as to what the API function needs that for. It sounds like an X/Y problem. Nested string arrays like that are sloppy, so it's likely you can better achieve whatever you are doing with a different approach.
     
  12. Offline

    0verFull

    Problems resolved, the line of code was in a for loop when it should not. Sorry to waste your time, careless error

    Sorry and thanks!
     
Thread Status:
Not open for further replies.

Share This Page