0

I have a thread with some parser of an array. I have an array of String splitted by white-spaces from other String, cleared empty fields and now I am trying to clear all colons and equals from it. So I have created method that uses for-each with 'String s' in that array. Than I have another for-each with 'char c' in that String converted to char array. And here's that exception. Here's the code:

    public String[] clearColons(String[] in) {
            List<String> output = new ArrayList<>();

            for (String s : in) {
                    StringBuilder out = new StringBuilder();

                    for (char c : s.toCharArray()) {
                        if (c != ':' && c != '=') {
                                out.append(c);
                        }
                    }

                    output.add(out.toString());
            }

            return output.toArray(in);
        }

Please help!

DrunkCoder
  • 379
  • 2
  • 9
  • check if `in` is null. – TheLostMind Aug 23 '14 at 06:14
  • `in` might be null. If so `s.toCharArray()` will generate `NullPointerException`. – Darshan Lila Aug 23 '14 at 06:15
  • 4
    where is the stack trace? Post the complete stack trace of exception here and someone will show direction in 2 seconds. – Nazgul Aug 23 '14 at 06:16
  • better use `s.replaceAll("[:=]","");`. No need of `StringBuilder` – Braj Aug 23 '14 at 06:17
  • 1
    Whenever there is a word "Exception" in your question , you should consider posting the Exception trace log.. – Stunner Aug 23 '14 at 06:19
  • Exception in thread "main" java.lang.NullPointerException at com.unicyde.mixell.flow.Flow.clearColons(Flow.java:190) at com.unicyde.mixell.flow.Flow.declareVar(Flow.java:164) at com.unicyde.mixell.flow.Flow.keywordSwitcher(Flow.java:118) at com.unicyde.mixell.flow.Flow.mainLoop(Flow.java:95) at com.unicyde.mixell.flow.Flow.main(Flow.java:68) Java Result: 1 – DrunkCoder Aug 23 '14 at 06:32
  • So, read the answer to the linked duplicate question, and ask yourself: what could be null and thus cause a NullPointerException at line 190 of Flow.java? – JB Nizet Aug 23 '14 at 06:44

0 Answers0