Android: NullpointerException at vibrate
<p>I am using the following code , but its giving the nullpointer exception at vibrate.</p>

<pre><code>public Server(DroidGap gap, WebView view)    //constructor
        {
            mAppView = view;
            mGap = gap;
        }


    public Server(Context context)            //constructor
        {
            mcontext=context;

        }

public void run()  //run method

        {

                    try {

                        InetAddress serveradd =  InetAddress.getByName(serveraddress);
                        } 
                     catch (UnknownHostException e1) 
                        {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                        } 


                    DatagramPacket packet=new DatagramPacket(buf,buf.length);

                    try
                        {
                            c.socket.receive(packet);

                            dat=new String(packet.getData());

                            if(dat!=null)
                                {

                                ((Vibrator)mGap.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(800);

                                cordovaExample.activity.sendJavascript("displayreciever('"+dat+"')");


                                }

                            Log.d("UDP", "s: ReceivedJI: '" + new String(packet.getData()) + "'");

                          }                  //end of try block



                     catch (IOException e) 

                           {

                                e.printStackTrace();

                           }       
                                 //end of catch block






                }  //end of run method
</code></pre>

<p>I am getting nullpointer Exception at the followingline</p>

<pre><code>((Vibrator)mGap.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(800);
</code></pre>

<p>I am not able to find out the reason</p>

<p>Any help will be appreciated,</p>
