public void onLocationChanged(Location loc)
{
GeoPoint point = new GeoPoint((int)(loc.getLatitude() * 1E6),
(int)(loc.getLongitude() * 1E6));
String Text = "My current location is: " +
"Latitud =" + loc.getLatitude() + "Longitud =" + loc.getLongitude();
Toast.makeText(getApplicationContext(),
Text, Toast.LENGTH_SHORT).show();
double x = loc.getLatitude();
double y = loc.getLongitude();
try {
outToServer.writeDouble(x);
outToServer.writeDouble(y);
} catch(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mc.animateTo(point);
}
我已在第一个活动中打开套接字,然后单击下一步。这是我的第二个,我想将lat和日志数据发送到服务器。
05-31 02:05:41.055: DEBUG/StatusBarPolicy(180): [GPS ICON] GPS_ENABLED_CHANGE_ACTION or GPS_FIX_CHANGE_ACTION
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): FATAL EXCEPTION: main
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): java.lang.NullPointerException
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at yaraby.y.yarab$MyLocationListener.onLocationChanged(yarab.java:354)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:191)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:124)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:140)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at android.os.Looper.loop(Looper.java:123)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at android.app.ActivityThread.main(ActivityThread.java:4633)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at java.lang.reflect.Method.invoke(Method.java:521)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-31 02:05:41.125: ERROR/AndroidRuntime(6365): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
DataOutputStream outToServer
是null
。您需要创建流。
Socket socket= new Socket(<IP>,<PORT>);
DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());