0

I am trying to launch a new activity by passing intents as data

  • I have posted the log
  • How to resolve the errors

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();
        }
    }
}

Log::

        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 

line is RatingDescriptionFilterActivity.java:87 is

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

Problem is arising in getting the value from seek bars in filters.java

How to debug the errors

Community
  • 1
  • 1
smriti3
  • 821
  • 2
  • 15
  • 34
  • Did you tried to print the "newurl".Can you post whats is priting?? – Subburaj Oct 21 '13 at 13:12
  • DISTANCE_FILTER, RATE_FILTER, PRICE_FILTER, TYPE_FILTER. At least one of these is null. Log.d() these variables after you get them in onCreate to see the values. – Carnal Oct 21 '13 at 13:12
  • one between DISTANCE_FILTER, RATE_FILTER, PRICE_FILTER and TYPE_FILTER is null. If I were in you I will start checking where do you assign those values – Blackbelt Oct 21 '13 at 13:13
  • 1
    Do you know what a NullPointerException is and how to debug/solve them? If not, [please read this](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception/218390#218390) – Simon Forsberg Oct 21 '13 at 13:13

1 Answers1

1

I hope you are using Eclipse, so you can put breakpoint on this line and debug your application, you can also use expressions view to find out value for each of DISTANCE_FILTER, RATE_FILTER, PRICE_FILTER, TYPE_FILTER

here are steps to debug android application

1) you need to set android:debuggable="true" in your application in the AndroidManifest.xml. if you haven't set that setting, debugging will not be enabled.

2) either start the app by right clicking on the project and select Debug As->Android Application or by running it normally and later in the DDMS perspective select the running app in your devices pane and click on the green bug.

3) once a breakpoint has been hit you can step over (f6) or step into (f5) (check the Run menu for more commands).

Cheers!!!

Sourabh Saldi
  • 3,742
  • 6
  • 32
  • 57