-7

I am unable to find the error in my android application. I have read guides on how to read logcat errors but the problem with my error is that it is not from my classes. Could someone give me some idea on how I could debug this?

I have a two spinners in my layout. One of which has an string array fixed for its list of items inside. The other spinner's items are generated dynamically with some code. The program actually runs fine on the emulator. But when I run on my device, a toggle button which doesnt uses the spinner crashes the application. If there is any more detail or information that I need to share to debug, do let me know.

Sorry I did post the logcat but the image disappeared. The complete logcat is below now. logcat logcat2

And here is the toggle button which crashed the application when pressed.

public void onToggleClicked(View view) { Context context = getApplicationContext();

    if (checkConnectivity()) {
        // Is the toggle on?
        boolean on = tglbtn.isChecked();

        if (on) {
            startRepeatingTask();
        } else {
            stopRepeatingTask();
        }
    }
    else {
        Toast.makeText(context, "Please check your internet connection.", Toast.LENGTH_LONG).show();
    }
}

These are the two methods....

Runnable mStatusChecker = new Runnable() {
          @Override 
          public void run() {
            //updateStatus(); //this function can change value of mInterval.
              new updateBuses().execute();
              mHandler.postDelayed(mStatusChecker, mInterval);
          }
        };

        void startRepeatingTask() {
          mStatusChecker.run(); 
        }

        void stopRepeatingTask() {
          mHandler.removeCallbacks(mStatusChecker);
        }

The updateBuses class is an Asynctask which has nothing to do with my spinners. This is the method which populates my spinner.

private void plotBuses(ArrayList<MyMarker> markers) {
        Log.d("Checking Array", mMyMarkersArray.toString());
        if(markers.size() > 0)
        {
            for (MyMarker myMarker : markers)
            {
                // Create bus marker with custom icon and other options
                Log.d("plotting", myMarker.getmLabel());
                MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()));
                markerOption.title(myMarker.getmLabel());
                markerOption.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_bus));

                Marker currentMarker = map.addMarker(markerOption);
                mMarkersHashMap.put(currentMarker, myMarker);
            }

            Log.d("check hashmap:", mMarkersHashMap.toString());
            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
            (this, android.R.layout.simple_spinner_item,spinnerList);

            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner1.setAdapter(dataAdapter);
        }
    }

The spinnerList is not null because my spinner populates with the items inside my spinner.

Community
  • 1
  • 1
Bilal Soomro
  • 661
  • 1
  • 7
  • 12

1 Answers1

0

According to documentation the purpose of the method makeAndAddView() that throws NullPointerException:
Obtain a view, either by pulling an existing view from the recycler or by getting a new one from the adapter.
This method tries to get the View by accessing adapter that is bound to this Spinner.

P.S.
What API version do you use during building? What are the AVD and actual phone Android versions you are testing on?

A.Vynohradov
  • 276
  • 1
  • 8
  • Sorry for the late reply. I am using API 19. The AVD is a nexus 4 with API 19 but my phone is the Huawei U8150 IDEOS which is running on a custom rom of android version ICS. The problem only arises on this phone. It works on my emulator and also my friends Galaxy S4 device. So i guess no point in trying to debug this problem as its working on newer devices. – Bilal Soomro Jul 15 '14 at 16:37
  • 1
    Custom Android means that documented features might not work as you expect. Try more devices, but you're right - there's no sense to search for bug if your app is working properly on native Android devices. – A.Vynohradov Jul 16 '14 at 06:53