Google TV socket connection problem

3 views
Skip to first unread message

Sayeed Chowdhury

unread,
Jul 8, 2012, 10:08:57 AM7/8/12
to 2012-lonh...@googlegroups.com, Md. Wasiq Islam
Hi Jerek,

As requested, please find the code snippets which are running on same Main activity thread. The following code is for the server side which we are trying to run on Google TV. 


try{
     serverSocket = new ServerSocket(4444);
   } catch (IOException e) {
     Toast.makeText(this, "hello man"+e, Toast.LENGTH_SHORT).show();
      e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
   }
Toast.makeText(this, "Server Started", Toast.LENGTH_SHORT).show();

while (true) {
            try{
                clientSocket = serverSocket.accept();
                inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
                bufferedReader = new BufferedReader(inputStreamReader);
                message = bufferedReader.readLine();
                Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
                inputStreamReader.close();
                clientSocket.close();

            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                Toast.makeText(this, "Probleme in message reading", Toast.LENGTH_SHORT).show();
            }
        }




Error_Logs:

8 08:08:21.526: ERROR/AndroidRuntime(12373): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MyActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
        at android.app.ActivityThread.access$1500(ActivityThread.java:124)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1016)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:132)
        at android.app.ActivityThread.main(ActivityThread.java:4083)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:491)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at com.example.MyActivity.onCreate(MyActivity.java:40)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1732)
        ... 11 more

Regards
Sayeed & Wasiq
Reply all
Reply to author
Forward
0 new messages