0

I have public class MapActivity extends Activity implements LocationListene where in onCreate method I want to load:

protected void onCreate(Bundle savedInstanceState) {

        try {
            super.onCreate(savedInstanceState);   
            setContentView(R.layout.mapview);

            ...
        }
}

mapview.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/ll_mapView"
              android:background="@android:color/white">

   <another_working_layout_here>

    <map.MyLocation
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    </map.MyLocation>

</LinearLayout>

And as a is loaded View from class:

public class MyLocation extends View {
    Paint paint = new Paint();

    public MyLocation(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(100, 100, 100, paint);
        this.invalidate();
    }
}

In general I want to read from android gps with onLocationChanged method in mapActivity, add points of change, and later print it on extended view done in class MyLocation extends View with onDraw method. I'm sure I dont fully understand this concept but has no idea how to do this in different way.

My error is:

10-28 16:06:40.147: ERROR/myException(2869): android.view.InflateException: Binary XML file line #26: Error inflating class map.MyLocation
10-28 16:07:06.478: ERROR/ActivityManager(1120): ANR in com.example.gps_3 (com.example.gps_3/activities.MapActivity)
        Reason: keyDispatchingTimedOut
        Load: 0.26 / 0.25 / 0.76
        CPU usage from 39586ms to 535ms ago:
        2.2% 950/adbd: 0% user + 2.2% kernel
        0% 932/yaffs-bg-1: 0% user + 0% kernel
        0.1% 2869/com.example.gps_3: 0% user + 0.1% kernel / faults: 18 minor
        0.1% 1120/system_server: 0% user + 0% kernel
        0% 1391/com.android.phone: 0% user + 0% kernel / faults: 92 minor
        0% 930/yaffs-bg-1: 0% user + 0% kernel
        0% 1281/com.android.systemui: 0% user + 0% kernel / faults: 6 minor
        0% 1404/com.android.launcher: 0% user + 0% kernel
        0% 2789/com.android.browser: 0% user + 0% kernel / faults: 89 minor
        48% TOTAL: 0.6% user + 45% kernel + 1.8% softirq
        CPU usage from 403ms to 914ms later:
        1.9% 1120/system_server: 0% user + 1.9% kernel
        100% TOTAL: 0% user + 100% kernel
10-28 16:12:04.312: ERROR/dalvikvm(1120): JIT code cache full
10-28 16:12:04.322: ERROR/InputDispatcher(1120): channel 'b353cf20 com.example.gps_3/activities.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
10-28 16:12:04.322: ERROR/InputDispatcher(1120): channel 'b350af88 com.example.gps_3/activities.MapActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
10-28 16:12:05.092: ERROR/jdwp(2914): Failed sending reply to debugger: Broken pipe
10-28 16:13:04.613: ERROR/myException(2914): android.view.InflateException: Binary XML file line #26: Error inflating class map.MyLocation

EDIT:

Exception is called in:

  @Override
    protected void onCreate(Bundle savedInstanceState) {

        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.mapview);
            myLocationManager = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
            myLocationLister = this;
            myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, myLocationLister);
        } catch (Exception e) {
            Log.e("myException", e.toString());      
        }

    }

by setContentView(R.layout.mapview); line.

I would appreciate any ideas. Thanks

Problem was with missing constructor:

public MyLocation(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

Connected helpfull topic: Do I need all three constructors for an Android custom view?

Community
  • 1
  • 1
Jacob
  • 14,949
  • 19
  • 51
  • 74
  • you should not call invalidate from onDraw. This might be a problem. – Leonidos Oct 28 '13 at 20:43
  • Nah, its not the case. – Jacob Oct 29 '13 at 06:59
  • Are you sure that 'map.MyLocation' is correct path? And I can't see 2 other constructors for your custom view. All views generally should have 3 standart constructors. And still you should not call invalide from onDraw ) – Leonidos Oct 29 '13 at 07:04
  • 'map.MyLocation' IS correct path because mostly when we write code, to improve our 'efficiency' we(I) use enviroment snippets which would not allow you to use incorrect path, unless you use windows notepad to develop. – Jacob Oct 29 '13 at 14:13

0 Answers0