0

我站在这个问题上,我想不通。我有这个应用程序,它在 Galaxy S3 和 Wildfire 上都运行,但是当我试图在 Galaxy S2 上运行它时,我遇到了错误。Galaxy S3 运行 4.1.2,Wilfire 运行 2.2.1,Galaxy S2 运行 2.3.3 android 操作系统。

问题 有一个进度对话框,它停止并且应用程序存在错误已关闭但我不明白就像我之前提到的它在 2 设备上工作但不是在 Galaxy S2 上。这是我 的 logcat 错误:

    04-03 11:02:42.010: E/AndroidRuntime(12339): FATAL EXCEPTION: AsyncTask #1
    04-03 11:02:42.010: E/AndroidRuntime(12339): java.lang.RuntimeException: An error occured while executing doInBackground()
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.lang.Thread.run(Thread.java:1019)
    04-03 11:02:42.010: E/AndroidRuntime(12339): Caused by: java.lang.NullPointerException
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at dk.tankegang.skraldespand.AlleKommuner$LoadAllProducts.doInBackground(AlleKommuner.java:138)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at dk.tankegang.skraldespand.AlleKommuner$LoadAllProducts.doInBackground(AlleKommuner.java:1)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    04-03 11:02:42.010: E/AndroidRuntime(12339):    ... 4 more
    04-03 11:02:46.975: E/WindowManager(12339): Activity dk.tankegang.skraldespand.AlleKommuner has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40534248 that was originally added here
    04-03 11:02:46.975: E/WindowManager(12339): android.view.WindowLeaked: Activity dk.tankegang.skraldespand.AlleKommuner has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40534248 that was originally added here
    04-03 11:02:46.975: E/WindowManager(12339):     at android.view.ViewRoot.<init>(ViewRoot.java:266)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:174)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:117)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.Dialog.show(Dialog.java:241)
    04-03 11:02:46.975: E/WindowManager(12339):     at dk.tankegang.skraldespand.AlleKommuner$LoadAllProducts.onPreExecute(AlleKommuner.java:126)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.os.AsyncTask.execute(AsyncTask.java:391)
    04-03 11:02:46.975: E/WindowManager(12339):     at dk.tankegang.skraldespand.AlleKommuner.onCreate(AlleKommuner.java:63)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.os.Handler.dispatchMessage(Handler.java:99)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.os.Looper.loop(Looper.java:123)
    04-03 11:02:46.975: E/WindowManager(12339):     at android.app.ActivityThread.main(ActivityThread.java:3691)
    04-03 11:02:46.975: E/WindowManager(12339):     at java.lang.reflect.Method.invokeNative(Native Method)
    04-03 11:02:46.975: E/WindowManager(12339):     at java.lang.reflect.Method.invoke(Method.java:507)
     04-03 11:02:46.975: E/WindowManager(12339):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
     04-03 11:02:46.975: E/WindowManager(12339):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
     04-03 11:02:46.975: E/WindowManager(12339):    at dalvik.system.NativeStart.main(Native Method)

这是我正在使用的代码,类:

    public class AlleKommuner extends ListActivity {

SQLiteDatabase db;
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();

ArrayList<HashMap<String, String>> kommunerList;

private static String url_all_kommuner = "http://xxx.com";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_KOMMUNER = "kommuner";
private static final String TAG_KID = "kId";
private static final String TAG_KNAME = "kName";
private static final String TAG_KURL = "kUrl";

// products JSONArray
JSONArray kommuner = null;
  String TAG = "LEYTH Alle Kommuner";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.all_products);


    // Hashmap for ListView
    kommunerList = new ArrayList<HashMap<String, String>>();

    // Loading products in Background Thread
    new LoadAllProducts().execute();

    // Get listview
    ListView lv = getListView();

    // on seleting single product
    // launching Edit Product Screen
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

            db = openOrCreateDatabase("value.db", Context.MODE_PRIVATE, null); // optional CursorFactory

            String kUrl = ((TextView) view.findViewById(R.id.kUrl)).getText().toString();

            Intent in = new Intent(getApplicationContext(), EnkeltView.class);
            in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            db.execSQL("INSERT INTO startValue (myValue, myUrl) VALUES (1, "+"'" + kUrl +"'"+")");
            db.close();

            finish();
            startActivityForResult(in, 100);
            }    
    });

    ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Do work to refresh the list here.
            new LoadAllProducts().execute();
            Log.d(TAG, "Here iam 2");

        }
    });

}

// Response from Edit Product Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if result code 100
    if (resultCode == 100) {
        // if result code 100 is received 
        // means user edited/deleted product
        // reload this screen again
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }
}

class LoadAllProducts extends AsyncTask<String, String, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(AlleKommuner.this);
        pDialog.setMessage("Vent Venligst..");
        pDialog.setTitle("Henter Kommuner");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(url_all_kommuner, "GET", params);

        try {
                        // products found
                // Getting Array of Products
                kommuner = json.getJSONArray(TAG_KOMMUNER);

                kommunerList.clear();

                // looping through All Products
                for (int i = 0; i < kommuner.length(); i++) {
                    JSONObject c = kommuner.getJSONObject(i);

                    // Storing each json item in variable
                    String k_id = c.getString(TAG_KID);
                    String k_name = c.getString(TAG_KNAME);
                    String k_url = c.getString(TAG_KURL);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_KID, k_id);
                    map.put(TAG_KNAME, k_name);
                    map.put(TAG_KURL, k_url);


                    Log.v(TAG, "this is kUrl --> ; " + k_url + " --- And this is TAG --> " + TAG_KURL);


                    // adding HashList to ArrayList
                    kommunerList.add(map);
                }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        // updating UI from Background Thread
        runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */
                ListAdapter adapter = new SimpleAdapter(
                        AlleKommuner.this, kommunerList,
                        R.layout.list_item, new String[] { TAG_KID,
                                TAG_KNAME, TAG_KURL},
                        new int[] { R.id.kId, R.id.name, R.id.kUrl });
                // updating listview
                setListAdapter(adapter);
            }
        });

        ((PullToRefreshListView) getListView()).onRefreshComplete();

    }

}
4

1 回答 1

1

json 在这一行为空。jParser.makeHttpRequest 在这些设备上失败。检查 jParser.makeHttpRequest 中发生了什么以及可能导致问题的原因。也许是互联网连接,也许是别的东西。它应该抛出异常,如果没有,请检查服务器响应状态代码。此外,您可能想要注销响应字符串并查看您得到的结果。

于 2013-04-03T09:43:25.830 回答