使用意图启动活动时出现日志错误

时间:2013-10-21 13:08:35

标签: java android android-intent

我试图通过将意图作为数据传递来启动一项新活动

  • 我已发布日志
  • 如何解决错误

RatingDescriptionFilterActivity.java

public class RatingDescriptionFilterActivity extends Activity {
    // Declare Variables
    JSONObject jsonobject;
    JSONArray jsonarray;
    ListView listview;
    ListViewAdapter adapter;
    ProgressDialog mProgressDialog;
    ArrayList<HashMap<String, String>> arraylist;
    static String NAME = "rank";
    static String TYPE = "country";
    static String DISTANCE = "distance";
    static String RATING = "rating";
    static String FLAG = "flag";

    private String url = "----------------- url----------";

    String TYPE_FILTER;
    String PRICE_FILTER;
    String RATE_FILTER;
    String DISTANCE_FILTER;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from listview_main.xml
        setContentView(R.layout.listview_main);

        //Bundle extras = getIntent().getExtras();

        TYPE_FILTER = getIntent().getStringExtra("REST1");
        PRICE_FILTER = getIntent().getStringExtra("PriceBar");
        RATE_FILTER = getIntent().getStringExtra("DistanceBar");
        DISTANCE_FILTER = getIntent().getStringExtra("RatingBar");




        // Locate the listview in listview_main.xml
        listview = (ListView) findViewById(R.id.listview);

        // Execute DownloadJSON AsyncTask
        new DownloadJSON().execute();
    }

    // DownloadJSON AsyncTask
    private class DownloadJSON extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(RatingDescriptionFilterActivity.this);
            // Set progressdialog title
            //mProgressDialog.setTitle("Fetching the information");
            // Set progressdialog message
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // Create an array
            arraylist = new ArrayList<HashMap<String, String>>();
            // Retrieve JSON Objects from the given URL address


            String newurl = "?" + "Key=" + DISTANCE_FILTER.trim() + "&Key1=" + RATE_FILTER.trim() + "&Key2=" + PRICE_FILTER.trim() + "&Key3=" + TYPE_FILTER.trim();

            Log.i ("newurl", newurl.toString ());
            jsonobject = JSONfunctions.getJSONfromURL("------------url-----------"+newurl);

            Log.i ("jsonobject", jsonobject.toString ());
            try {
                // Locate the array name in JSON
                jsonarray = jsonobject.getJSONArray("restaurants");

                for (int i = 0; i < jsonarray.length(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    jsonobject = jsonarray.getJSONObject(i);
                    // Retrive JSON Objects
                    map.put(RatingDescriptionActivity.NAME, jsonobject.getString("restaurantNAME"));
                    map.put(RatingDescriptionActivity.TYPE, jsonobject.getString("restaurantTYPE"));
                    map.put(RatingDescriptionActivity.FLAG, "-----url-----"+jsonobject.getString("restaurantIMAGE"));
                    map.put(RatingDescriptionActivity.DISTANCE, jsonobject.getString("restaurantDISTANCE"));
                    map.put(RatingDescriptionActivity.RATING, jsonobject.getString("restaurantRATING"));
                    map.put(RatingDescriptionActivity.PRICE, jsonobject.getString("restaurantPrice"));



                    // Set the JSON Objects into the array
                    arraylist.add(map);
                }
            } catch (JSONException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void args) {
            // Pass the results into ListViewAdapter.java
            adapter = new ListViewAdapter(RatingDescriptionFilterActivity.this, arraylist);
            // Set the adapter to the ListView
            listview.setAdapter(adapter);
            // Close the progressdialog
            mProgressDialog.dismiss();
        }
    }
}

日志 ::

        10-21 17:55:46.756: E/AndroidRuntime(1061): FATAL EXCEPTION: AsyncTask #2
10-21 17:55:46.756: E/AndroidRuntime(1061): java.lang.RuntimeException: An error occured while executing doInBackground()
10-21 17:55:46.756: E/AndroidRuntime(1061):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
10-21 17:55:46.756: E/AndroidRuntime(1061):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-21 17:55:46.756: E/AndroidRuntime(1061):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-21 17:55:46.756: E/AndroidRuntime(1061):     at 

RatingDescriptionFilterActivity.java:87

String newurl = "?" + "Key=" + DISTANCE_FILTER.trim() + "&Key1=" + RATE_FILTER.trim() + "&Key2=" + PRICE_FILTER.trim() + "&Key3=" + TYPE_FILTER.trim();

filters.java

中获取搜索栏的值时出现问题

如何调试错误

1 个答案:

答案 0 :(得分:1)

我希望你使用Eclipse,所以你可以在这一行放置断点并调试你的应用程序,你也可以使用表达式视图找出每个DISTANCE_FILTER, RATE_FILTER, PRICE_FILTER, TYPE_FILTER的值

以下是调试Android应用程序的步骤

1)您需要在AndroidManifest.xml中的应用程序中设置android:debuggable =“true”。如果您尚未设置该设置,则不会启用调试。

2)通过右键单击项目启动应用程序并选择Debug As-&gt; Android Application或正常运行它,稍后在DDMS透视图中选择设备窗格中正在运行的应用程序并单击绿色错误。

3)一旦断点被​​击中,你可以跳过(f6)或步入(f5)(检查运行菜单以获取更多命令)。

干杯!!!