我正在使用以下代码,但它在振动时给出了空指针异常。
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
我在以下行收到空指针异常
((Vibrator)mGap.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(800);
我无法找出原因
任何帮助将不胜感激,