• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple question! I keep getting NullPointerException error!  RSS feed

 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realize that the design is DOWNRIGHT TERRIBLE, trust me, it's the first thing I'm going to work on as soon as I get the code running.

But for the moment, I'm just trying to figure out why this doesn't work!

I have a class that does audio-related stuff, "Audio".

I have another class to take care of networking, "Networking". There is no "client" or "server" here, the setUpNetworking() method asks me if I want to listen or connect, and the port numbers either, I open two processes, on one I listen, on the other I connect.

Here's part of the Audio class.



Now that two different "machines" are connected, I want them both to be ready to receive any data one sends to the other, which is what the "receiveThread" thread is for.



Ok, even if my totally awesome casting is totally ****ed up, why do I get a NullPointerException? The networking has been established!

I tried checking the socket's connection using "isBound", same error.

I KNOW the connection is being established because the setUpNetworking prints stuff like "listening" and "connection successful" on the console.

Please, someone help me with this
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you haven't shown us the bit of code that assigns something to the memb er variable "networking". Maybe that's in the setupNetworking() method? The first thing I'd suspect is that this assignment is never being made, and "networking" itself is null. A simple "println()" could confirm this.
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that this is EDITED code to make it more readable to you guys.

I got the capture/playback code from another website and just adding stuff of my own, trying to add functionality. That would explain the "START MY CODE" and "END MY CODE" comments, those are the lines I coded (obviously, since they're terrible ^_^)



I realize how terrible to logic is, I'm working with trials-and-error, I just want this to work, I'll sort out all the other issues afterwards, learn more about concurrency and better design and all that, for now, I just want to know why I'm getting the NullExceptionError, which, btw, is being generated for both processes.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it matter that the instance of Networking on which you're calling "setupNetworking()" is not the same one on which you're calling getSocketInputStream() ?

The NullPointerException stack trace should tell you exactly which line is causing the exception in each class that's involved. Looking at those line numbers in those classes should give you some hints about what's happening. Question everything -- put print statements in the code right before the line numbers mentioned in the stack trace; use those print statements to verify that things you think aren't null, really aren't.
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were right about the different instances, thank you, I would have never discovered that one.

Still having trouble with NullExceptions when it comes to reading/writing
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!