0

嘿伙计们,我正在使用 gps 位置,所以我正在获取坐标,我现在需要将这些坐标传递给我的 Web 服务并将其存储到我的数据库中。但是我无法以正确的方式存储它,我认为我得到的数据对于数据库来说太大了,这就是我试图将坐标转换为十进制格式的原因。当我将 DecimaFormat 方法放入我的代码中时,我遇到了一些错误,你们能帮帮我吗?

这些是错误:

03-13 22:03:16.733: E/WindowManager(1018): Activity com.example.projectthesis.Mapping2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41319870 that was originally added here
03-13 22:03:16.733: E/WindowManager(1018): android.view.WindowLeaked: Activity com.example.projectthesis.Mapping2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41319870 that was originally added here
03-13 22:03:16.733: E/WindowManager(1018):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
03-13 22:03:16.733: E/WindowManager(1018):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
03-13 22:03:16.733: E/WindowManager(1018):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
03-13 22:03:16.733: E/WindowManager(1018):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
03-13 22:03:16.733: E/WindowManager(1018):  at android.view.Window$LocalWindowManager.addView(Window.java:537)
03-13 22:03:16.733: E/WindowManager(1018):  at android.app.Dialog.show(Dialog.java:278)
03-13 22:03:16.733: E/WindowManager(1018):  at com.example.projectthesis.Mapping2$phpconnect.onPreExecute(Mapping2.java:190)
03-13 22:03:16.733: E/WindowManager(1018):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
03-13 22:03:16.733: E/WindowManager(1018):  at android.os.AsyncTask.execute(AsyncTask.java:511)
03-13 22:03:16.733: E/WindowManager(1018):  at com.example.projectthesis.Mapping2$GPSLocationListener.onLocationChanged(Mapping2.java:124)
03-13 22:03:16.733: E/WindowManager(1018):  at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:234)
03-13 22:03:16.733: E/WindowManager(1018):  at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:167)
03-13 22:03:16.733: E/WindowManager(1018):  at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:183)
03-13 22:03:16.733: E/WindowManager(1018):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 22:03:16.733: E/WindowManager(1018):  at android.os.Looper.loop(Looper.java:137)
03-13 22:03:16.733: E/WindowManager(1018):  at android.app.ActivityThread.main(ActivityThread.java:4424)
03-13 22:03:16.733: E/WindowManager(1018):  at java.lang.reflect.Method.invokeNative(Native Method)
03-13 22:03:16.733: E/WindowManager(1018):  at java.lang.reflect.Method.invoke(Method.java:511)
03-13 22:03:16.733: E/WindowManager(1018):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-13 22:03:16.733: E/WindowManager(1018):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-13 22:03:16.733: E/WindowManager(1018):  at dalvik.system.NativeStart.main(Native Method)

这些是我的代码(特别是在传递过程和 DecimalFormat 方法上):

class phpconnect extends AsyncTask<String, String, String> {
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Mapping2.this);
            pDialog.setMessage("Logging in..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected String doInBackground(String... args) {
            String strLatitude = Long.toString(ILatitude);
            String strLongitude = Long.toString(ILongitude);

            DecimalFormat df = new DecimalFormat("###.00000");
            String frmLat = df.format(strLatitude);
            String frmLong = df.format(strLongitude);
            // Building parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("latitude", frmLat));
            params.add(new BasicNameValuePair("longitude", frmLong));
            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);
            // check log cat fro response
            Log.d("Create Response", json.toString());
            try {
                int success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    // successfully updated
                    Intent i = new Intent(getApplicationContext(),
                            Mapping2.class);

                    startActivity(i);
                    // closing this screen
                    finish();
                } else {
                    // failed to create product
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
4

2 回答 2

1

我在您的代码中发现奇怪的是 ILatitude 和 ILongitude 显然属于这种Long类型。纬度和经度更好地表示为double值。我认为DecimalFormat这里并不真正需要,一个简单的String.valueOf(ILatitude);就足够了,考虑到你让 ILatitude 成为双倍。

于 2013-03-12T22:00:35.217 回答
0

您应该将 along或 a传递double给该format方法。当您传递一个String对象时,该方法会抛出一个IllegalArgumentException导致您的doInBackground方法过早结束的方法。因此,您在其中创建的对话框onPreExecute不会被关闭并被泄露。

于 2013-03-12T20:41:46.877 回答