-1

I have a class where I have implemented runnable and I start the thread in one of the function of this class, and I call this function from the main activity,I create the object of this class and call the method of thread class.My main activity code from where I call this class method is:

  broadcast broadcastobject.threadfunc(messages);

My class where I create threads is:

  public class broadcast  {

private DatagramSocket socket;
String str;
private static final int TIMEOUT_MS = 10;
WifiManager mWifi;
EditText et;
DatagramPacket packet;
Button bt;
private static final int SERVERPORT = 11111;
private static final String SERVER_IP = "192.168.1.255";


public void threadfunc(String message){
    str=message;
                new Thread(new ClientThread()).start();
}

/*
 private InetAddress getBroadcastAddress() throws IOException {
        DhcpInfo dhcp = mWifi.getDhcpInfo();
        if (dhcp == null) {
          //Log.d(TAG, "Could not get dhcp info");
          return null;
        }

        int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
        byte[] quads = new byte[4];
        for (int k = 0; k < 4; k++)
          quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
        return InetAddress.getByAddress(quads);
      }

      */

class ClientThread implements Runnable {

    @Override
    public void run() {


        try {
            socket = new DatagramSocket(SERVERPORT);

            socket.setBroadcast(true);
    //              socket.setSoTimeout(TIMEOUT_MS);
        } catch (SocketException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

            InetAddress serverAddr = null;
            try {


                serverAddr = InetAddress.getByName(SERVER_IP);


            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

           packet = new DatagramPacket(str.getBytes(), str.length(),serverAddr,SERVERPORT);

            try {

                    socket.send(packet);

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    } 

    }

}

My log cat is:

   08-31 21:55:56.277: D/gralloc_goldfish(1669): Emulator without GPU emulation detected.
   08-31 21:56:02.467: D/AndroidRuntime(1669): Shutting down VM
   08-31 21:56:02.467: W/dalvikvm(1669): threadid=1: thread exiting with uncaught  exception (group=0x409961f8)
   08-31 21:56:02.517: E/AndroidRuntime(1669): FATAL EXCEPTION: main
   08-31 21:56:02.517: E/AndroidRuntime(1669): java.lang.NullPointerException
   08-31 21:56:02.517: E/AndroidRuntime(1669):  at soft.b.peopleassist.Send$1.onClick(Send.java:113)
    08-31 21:56:02.517: E/AndroidRuntime(1669):     at android.view.View.performClick(View.java:3480)
   08-31 21:56:02.517: E/AndroidRuntime(1669):  at android.view.View$PerformClick.run(View.java:13983)
    08-31 21:56:02.517: E/AndroidRuntime(1669):     at android.os.Handler.handleCallback(Handler.java:605)
    08-31 21:56:02.517: E/AndroidRuntime(1669):     at android.os.Handler.dispatchMessage(Handler.java:92)
     08-31 21:56:02.517: E/AndroidRuntime(1669):    at android.os.Looper.loop(Looper.java:137)
       08-31 21:56:02.517: E/AndroidRuntime(1669):  at android.app.ActivityThread.main(ActivityThread.java:4340)
      08-31 21:56:02.517: E/AndroidRuntime(1669):   at java.lang.reflect.Method.invokeNative(Native Method)
      08-31 21:56:02.517: E/AndroidRuntime(1669):   at java.lang.reflect.Method.invoke(Method.java:511)
     08-31 21:56:02.517: E/AndroidRuntime(1669):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
     08-31 21:56:02.517: E/AndroidRuntime(1669):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   08-31 21:56:02.517: E/AndroidRuntime(1669):  at dalvik.system.NativeStart.main(Native Method)
Nerd
  • 9
  • 4
  • Dud you posted the same code. The same stack trace. You might be asking a slightly different question but is 99% duplicate. – Gray Aug 31 '13 at 22:13
  • no totally different code ,you can see the function where the thread is started ,its not the class with thread extended which is totally different thing. @Gray – Nerd Aug 31 '13 at 22:17

1 Answers1

1

This simply means that the emulator you are using does not have GPU emulation enabled. In Android SDK Tools R15 you can enable GPU emulation.You need to create a new emulator virtual device and set GPU emulation to true in Hardware properties.

enter image description here

Joel Dean
  • 2,444
  • 5
  • 32
  • 50