Android モバイルから MySQL wamp サーバーに座標を送信しようとしています。デスクトップコンピューターでは問題なく動作しますが、ラップトップに移動すると、アクティビティが応答しないという例外が発生します。onclicklistener メソッドの前にトーストメッセージを追加して修正しようとしました。うまく機能していますが、2 番目のトーストは機能しません (2 番目のトーストは onclick メソッド ブロックにあります)。どうすればこれを解決できますか?
コード:
Toast.makeText(getApplicationContext(), "msg 1", Toast.LENGTH_SHORT).show();
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// create class object
Toast.makeText(getApplicationContext(), "msg 2", Toast.LENGTH_SHORT).show();
gps = new GPSTracker(AndroidGPSTrackingActivity.this);
// check if GPS enabled
if(gps.canGetLocation()){
String latitude = String.valueOf(gps.getLatitude());
String longitude = String.valueOf(gps.getLongitude());
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("latitude", latitude));
params.add(new BasicNameValuePair("longitude", longitude));
// \n is for new line
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params);
Log.d("Create Response", json.toString());
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
}
}
});
2番目のもの:
public void showSettingsAlert(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
// Setting Dialog Title
alertDialog.setTitle("GPS is settings");
// Setting Dialog Message
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
// On pressing Settings button
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
ボタンを押した後のlogcat:
05-12 00:03:30.709: ERROR/ActivityManager(59): ANR in com.example.gpstracking (com.example.gpstracking/.AndroidGPSTrackingActivity)
05-12 00:03:30.709: ERROR/ActivityManager(59): Reason: keyDispatchingTimedOut
05-12 00:03:30.709: ERROR/ActivityManager(59): Load: 0.67 / 1.06 / 0.49
05-12 00:03:30.709: ERROR/ActivityManager(59): CPU usage from 7935ms to 64ms ago:
05-12 00:03:30.709: ERROR/ActivityManager(59): system_server: 15% = 7% user + 8% kernel / faults: 172 minor 4 major
05-12 00:03:30.709: ERROR/ActivityManager(59): ple.gpstracking: 5% = 0% user + 5% kernel / faults: 28 minor 5 major
05-12 00:03:30.709: ERROR/ActivityManager(59): adbd: 3% = 0% user + 3% kernel
05-12 00:03:30.709: ERROR/ActivityManager(59): m.android.phone: 1% = 0% user + 1% kernel / faults: 139 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): logcat: 1% = 0% user + 0% kernel
05-12 00:03:30.709: ERROR/ActivityManager(59): ronsoft.openwnn: 0% = 0% user + 0% kernel / faults: 93 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): id.defcontainer: 0% = 0% user + 0% kernel / faults: 86 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): zygote: 0% = 0% user + 0% kernel / faults: 67 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): m.android.email: 0% = 0% user + 0% kernel / faults: 123 minor 2 major
05-12 00:03:30.709: ERROR/ActivityManager(59): m.android.music: 0% = 0% user + 0% kernel / faults: 78 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): android.protips: 0% = 0% user + 0% kernel / faults: 87 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): .quicksearchbox: 0% = 0% user + 0% kernel / faults: 94 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): com.svox.pico: 0% = 0% user + 0% kernel / faults: 59 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): kswapd0: 0% = 0% user + 0% kernel
05-12 00:03:30.709: ERROR/ActivityManager(59): ndroid.settings: 0% = 0% user + 0% kernel / faults: 112 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): d.process.acore: 0% = 0% user + 0% kernel / faults: 84 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): roid.alarmclock: 0% = 0% user + 0% kernel / faults: 85 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): com.android.mms: 0% = 0% user + 0% kernel / faults: 95 minor 1 major
05-12 00:03:30.709: ERROR/ActivityManager(59): qemud: 0% = 0% user + 0% kernel
05-12 00:03:30.709: ERROR/ActivityManager(59): ndroid.launcher: 0% = 0% user + 0% kernel / faults: 60 minor
05-12 00:03:30.709: ERROR/ActivityManager(59): TOTAL: 37% = 11% user + 25% kernel + 0% irq + 0% softirq
05-12 00:03:30.999: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 4749 objects / 237112 bytes in 237ms
05-12 00:03:31.039: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:31.289: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 346 objects / 19296 bytes in 163ms
05-12 00:03:31.519: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 313 objects / 14056 bytes in 214ms
05-12 00:03:31.519: INFO/dalvikvm-heap(59): Grow heap (frag case) to 4.862MB for 83464-byte allocation
05-12 00:03:31.739: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 86 objects / 4952 bytes in 206ms
05-12 00:03:31.949: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 45 objects / 86216 bytes in 196ms
05-12 00:03:31.949: INFO/dalvikvm-heap(59): Grow heap (frag case) to 4.974MB for 166912-byte allocation
05-12 00:03:32.159: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 10 objects / 464 bytes in 204ms
05-12 00:03:32.399: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 62 objects / 231752 bytes in 212ms
05-12 00:03:32.659: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 58 objects / 173848 bytes in 207ms
05-12 00:03:32.759: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.759: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.769: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.769: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.788: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.788: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.809: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.809: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.819: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.819: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.829: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.841: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.841: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.849: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.859: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.859: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.869: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.869: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.869: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.869: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.869: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.869: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.889: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.889: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.889: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.889: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.898: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.898: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.909: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:32.909: WARN/WindowManager(59): No window to dispatch pointer action 0
05-12 00:03:32.909: WARN/WindowManager(59): No window to dispatch pointer action 1
05-12 00:03:33.309: INFO/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x22b838:0x22b8f4] in 763754 ns
05-12 00:04:32.018: WARN/System.err(279): java.net.SocketException: The operation timed out
05-12 00:04:32.048: WARN/System.err(279): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
05-12 00:04:32.048: WARN/System.err(279): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
05-12 00:04:32.058: WARN/System.err(279): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
05-12 00:04:32.058: WARN/System.err(279): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
05-12 00:04:32.069: WARN/System.err(279): at java.net.Socket.connect(Socket.java:1055)
05-12 00:04:32.069: WARN/System.err(279): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
05-12 00:04:32.078: WARN/System.err(279): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
05-12 00:04:32.088: WARN/System.err(279): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-12 00:04:32.088: WARN/System.err(279): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-12 00:04:32.088: WARN/System.err(279): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-12 00:04:32.098: WARN/System.err(279): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-12 00:04:32.098: WARN/System.err(279): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-12 00:04:32.098: WARN/System.err(279): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-12 00:04:32.118: WARN/System.err(279): at com.example.gpstracking.JSONParser.makeHttpRequest(JSONParser.java:51)
05-12 00:04:32.118: WARN/System.err(279): at com.example.gpstracking.AndroidGPSTrackingActivity$1.onClick(AndroidGPSTrackingActivity.java:63)
05-12 00:04:32.128: WARN/System.err(279): at android.view.View.performClick(View.java:2408)
05-12 00:04:32.128: WARN/System.err(279): at android.view.View$PerformClick.run(View.java:8816)
05-12 00:04:32.128: WARN/System.err(279): at android.os.Handler.handleCallback(Handler.java:587)
05-12 00:04:32.158: WARN/System.err(279): at android.os.Handler.dispatchMessage(Handler.java:92)
05-12 00:04:32.158: WARN/System.err(279): at android.os.Looper.loop(Looper.java:123)
05-12 00:04:32.158: WARN/System.err(279): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 00:04:32.158: WARN/System.err(279): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 00:04:32.169: WARN/System.err(279): at java.lang.reflect.Method.invoke(Method.java:521)
05-12 00:04:32.169: WARN/System.err(279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 00:04:32.169: WARN/System.err(279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 00:04:32.169: WARN/System.err(279): at dalvik.system.NativeStart.main(Native Method)
05-12 00:04:32.188: ERROR/Buffer Error(279): Error converting result java.lang.NullPointerException
05-12 00:04:32.268: ERROR/JSON Parser(279): Error parsing data org.json.JSONException: End of input at character 0 of
05-12 00:04:32.268: DEBUG/AndroidRuntime(279): Shutting down VM
05-12 00:04:32.278: WARN/dalvikvm(279): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): FATAL EXCEPTION: main
05-12 00:04:32.308: ERROR/AndroidRuntime(279): java.lang.NullPointerException
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at com.example.gpstracking.AndroidGPSTrackingActivity$1.onClick(AndroidGPSTrackingActivity.java:65)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at android.view.View.performClick(View.java:2408)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at android.view.View$PerformClick.run(View.java:8816)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at android.os.Handler.handleCallback(Handler.java:587)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at android.os.Handler.dispatchMessage(Handler.java:92)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at android.os.Looper.loop(Looper.java:123)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at java.lang.reflect.Method.invoke(Method.java:521)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 00:04:32.308: ERROR/AndroidRuntime(279): at dalvik.system.NativeStart.main(Native Method)
05-12 00:04:32.358: WARN/ActivityManager(59): Force finishing activity com.example.gpstracking/.AndroidGPSTrackingActivity
05-12 00:04:32.948: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{44f8abd8 com.example.gpstracking/.AndroidGPSTrackingActivity}
05-12 00:04:43.728: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{44f8abd8 com.example.gpstracking/.AndroidGPSTrackingActivity}
05-12 00:05:50.939: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
05-12 00:09:32.479: INFO/Process(279): Sending signal. PID: 279 SIG: 9
05-12 00:09:33.379: INFO/ActivityManager(59): Process com.example.gpstracking (pid 279) has died.
05-12 00:09:33.398: INFO/WindowManager(59): WIN DEATH: Window{4500db48 com.example.gpstracking/com.example.gpstracking.AndroidGPSTrackingActivity paused=false}
05-12 00:09:33.458: WARN/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 279 uid 10032
05-12 00:09:33.678: WARN/GpsLocationProvider(59): Unneeded remove listener for uid 1000