다음 코드를 사용하고 있지만 진동시 nullpointer 예외가 발생합니다.Android : 진동시 NullpointerException
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
나는 아래 행에 nullpointer 예외를 얻고있다
((Vibrator)mGap.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(800);
나는
이 유 매니페스트 파일에 진동 권한을 추가 했 : 그냥 충돌 라인 전에
:
나에게의 출력을 알려주세요 :
이편집 ... 더 도움을 줄 ? – nayab
예 권한이 있습니다. 나는 다른 방법으로 진동 코드를 입력하여 작업을 시도했지만 실행 방법에서 해당 메서드를 호출했거나 실행 메서드에 해당 코드를 배치하면 해당 함수가 작동하지 않습니다. –