0

我正在尝试通过将意图作为数据传递来启动新活动

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

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

如何调试错误

4

1 回答 1

1

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

这是调试android应用程序的步骤

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

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

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

干杯!!!

于 2013-10-21T13:20:06.040 回答