Re: NullPointerException in Socket
Shawn Silverman <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <[email protected]> |
Yes, but that has a different scope. You're not actually assigning
anything to the field.
For example:
public class Example {
private Integer i;
public static void main(String[] args) {
Example e = new Example();
e.doSomething(); // This will print "6"
System.out.println(i); // This will print "null"
}
public void doSomething() {
Integer i = new Integer(6);
System.out.println(i); // This will print "6"
}
}
The solution is to change the creation line to:
listenSocket = new ServerSocket(SERVER_PORT);
Hope that clarifies things.
-Shawn
On 3-May-04, at 9:47 PM, Denis Yakovlev wrote:
> Hi,Shawn!!!
> Thank you very much for your answer.
> But I didn`t forget create ServerSocket at the begin of the programm.
> try{
> ServerSocket listenSocket= new ServerSocket(SERVER_PORT);
> System.out.println("Socket is cool!");
> }
> catch (IOException excp)
> {
> System.err.println("Unable to listen port" + SERVER_PORT + ":"
> +excp);
> }
> When I run this programm I see - "Socket is cool", but then at point
> described
> above I have NullPointerException.
> Have you more ideas?
> Excuse me ,but I need any help.
>
> Thanks a lot.
>
> 03 2004 21:29 :
>> Hi, Dennis. It looks like you've forgotten to create the ServerSocket
>> object:
>>
>> listenSocket = new ServerSocket(some_port);
>>
>> Regards,
>> -Shawn
>>
>> On 3-May-04, at 5:46 AM, Denis Yakovlev wrote:
>>> Hi, All!
>>> Can you help me with folowed problem? May be I just have poor
>>> knowledge in
>>> Java. So...
>>> The problem:
>>> public ServerSocket listenSocket ;
>>>
>>> public void serveTini() {
>>> Socket clientSocket;
>>> try{
>>> System.out.println("Point1");
>>> while(keepRunning){
>>> System.out.println("DeadPoint");
>>> clientSocket =
>>> listenSocket.accept();
>>> <----
>>>
>>> at this point I have an error:
>>>
>>> java.lang.NullPointerException
>>> in SockTiniTerm.serveTini(@JPC=b0010)
>>> in java.lang.System.???
>>>
>>> What should I do? Is syntax correct? Anybody please help me
>>>
>>>
>>>
>>> --
>>> Best regards
>>> Denis Yakovlev,
>
> --
> Best regards
> Denis Yakovlev,
> QA Engineer, SW-Soft
> Tel:89059564660
>
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini