I am trying to receive images over a network, I set up a server as follows
 ...

public class IServerActivity extends Activity {
   ServerSocket ss = null;
   Bitmap bp ;
   Thread myCommsThread = null;
   protected static final int MSG_ID = 0x1337;
   public static final int SERVERPORT = 6000;

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      //TextView tv = (TextView) findViewById(R.id.TextView01);       
      this.myCommsThread = new Thread(new CommsThread());
      this.myCommsThread.start();
   }

   @Override
   protected void onStop() {
      super.onStop();
      try {
         // make sure you close the socket upon exiting
         ss.close();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }

   Handler myUpdateHandler = new Handler() {
      public void handleMessage(Message msg) {
         switch (msg.what) {
         case MSG_ID:
            ImageView iv = (ImageView) findViewById(R.id.imageView01);
            iv.setImageBitmap(bp);;
            break;
         default:
            break;
         }
         super.handleMessage(msg);
      }
   };
   class CommsThread implements Runnable {
      public void run() {
         Socket s = null;
         try {
            ss = new ServerSocket(SERVERPORT );
         } catch (IOException e) {
            e.printStackTrace();
         }
         while (!Thread.currentThread().isInterrupted()) {
            Message m = new Message();
            m.what = MSG_ID;
            try {
               if (s == null)
                  s = ss.accept();
               bp= BitmapFactory.decodeStream(s.getInputStream());   
               myUpdateHandler.sendMessage(m);
            } catch (IOException e) {
               e.printStackTrace();
            }
         }
      }
   }


But it shows an error at runtime 

java.lang.NullPointerException 
E/AndroidRuntime(3047):atExample.IServer.IServerActivity$CommsThread.run(IServerActivity.java:68)


It shows null pointer exception at *s=ss.accept();* line. please help I 
don't know what is going wrong.


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to