-3

enter image description hereThis error started randomly after making a change in my program. There are no errors being diplayed by Netbeans.

I've encountered random errors in Netbeans 8.2 before that were usually resolved by deleting the cache but I have deleted the cache, restarted Netbeans and still get the same error.

I performed a clean and build to no avail.

The program ran. I can still compile it and run it on a separate machine, but Netbeans keeps giving me this error:

Exception in thread "main" java.lang.NullPointerException
at rss.RSSFeedParser.main(RSSFeedParser.java:157)
....\NetBeans\Cache\8.2\executor-snippets  \run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)

run.xml line 53

<java classpath="${classpath-translated}" classname="${classname}" dir="${work.dir}" jvm="${platform.java}" fork="true" failonerror="${java.failonerror}">

Update: I was catching a "NumberFormatException" on my try catch. Netbeans threw no errors on this previously until all of a sudden. I changed it to "Exception". The program Runs fine, but I have a suggestion from Netbeans to change it back to "NumberFormatException". What gives here? I thought that as long as the required exceptions were caught, there would not be a problem.

Please see attached screen shots. The problem The Solution

CoupFlu
  • 311
  • 4
  • 20
  • It clearly says there is a problem in RSSFeedParser.java:157, it means check the line no 157 of RSSFeedParser.java class. – Sambit May 14 '19 at 18:34
  • 1
    Please refer to the screen shot. There is no error in that program. – CoupFlu May 14 '19 at 18:39
  • Try to understand between compilation error and Exception. Exception occurs at runtime, it means when you run the program. – Sambit May 14 '19 at 18:40
  • In that line no either msEndPoint or msEndPoint.getTCPPorts() is null. While running, print those values. You will get the solution. – Sambit May 14 '19 at 18:42
  • You have a RunTime Exception : RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. So... Compile != Everything will work fine. – Gatusko May 14 '19 at 18:53
  • 1
    When you change your `catch` block to catch `Exception`s, you're catching any error that is an instance of `Exception`, which includes `NullPointerException` (the actual error that you're getting). When you were just catching `NumberFormatException`, the `NullPointerException` would be thrown somewhere inside the `try` block and the `catch` block would not catch it, because the catch was only supposed to catch `NumberFormatException`s. – Kröw May 14 '19 at 19:14

1 Answers1

0

The stacktrace you posted shows that there is an error at line 157 of the RSSFeedParser.java file. Your IDE isn't highlighting this line as erroneous because there aren't any syntactic or compile-time problems with your code.

String[] split = msEndpoint.getTcpPorts().split(",");

That code is "valid" in that it will compile, since the split(String) method of a String object returns an array of Strings, etc.

What's actually going wrong is that either msEndpoint is null, or msEndpoint.getTcpPorts() is returning null, so java ends up trying to invoke a method on null, and then throws a NullPointerException. (More on that here.)

Your IDE probably won't be able to figure out every possible error that your program can throw when it runs, before your program runs. It can show compile-time errors though. (More on the difference here.)

Try printing out the value of msEndpoint and then the value of msEndpoint.getTcpPorts() above your String[] split = ..... line:

if(...) {
   try {
      System.out.println(msEndpoint);
      System.out.println(msEndpoint.getTcpPorts());
      String[] split = msEndpoint.getTcpPorts.split(",");
      ...
   }
}

See which one of those has a value of null.

Kröw
  • 504
  • 2
  • 13
  • 31