0

I have a MapActivity and a Spinner. On Spinner there is OnItemSelected event which makes a content change of view. so i applied setContentView again on event of spinner onItemSelected because i changed the var content which is actually containing the data.but here it causing a crash Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity

so I did by doing this.

startActivity(new Intent(MapMultipleUsersActivity.this,MapMultipleUsersActivity.class));
finish();

i tried invalidate on mapview object but it was unsuccessful in its task.so what i need to do instead?.

my complete stack trace as follows

 FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
at android.app.Activity.setContentView(Activity.java:1647)
at com.app.milesoft.phonecash.MapMultipleUsersActivity$2.onItemSelected(MapMultipleUsersActivity.java:93)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
at android.widget.AdapterView.access$200(AdapterView.java:42)
at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at com.app.milesoft.map.multipleusers.MapLocationViewer.<init>(MapLocationViewer.java:28)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 20 more
Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a  
    MapActivity
at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:379)
at com.google.android.maps.MapView.<init>(MapView.java:280)
at com.google.android.maps.MapView.<init>(MapView.java:226)
at com.app.milesoft.map.multipleusers.MapLocationViewer.init(MapLocationViewer.java:45)
... 24 more

my MapActivity xml is as follows

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/home_container"
  android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <com.app.milesoft.map.multipleusers.MapLocationViewer
 android:id="@+id/map_location_viewer"
 android:layout_width="fill_parent"
android:layout_height="fill_parent" >

and my MapLOcation Class is as follows

public class MapLocationViewer extends LinearLayout {

private MapLocationOverlay overlay;

//  Known latitude/longitude coordinates that we'll be using.
private List<MapLocation> mapLocations;

private MapView mapView;
Context mcontext;

public MapLocationViewer(Context context, AttributeSet attrs) {
    super(context, attrs);
    mcontext=context;
    init();
}

public MapLocationViewer(Context context) {
    super(context);
    init();
}

public void init() {        

    setOrientation(VERTICAL);
    setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
           //this upper row xml is containing the Spinner View
    View v=View.inflate(getContext(), R.layout.map_upper_row, null);

    //mapView = new MapView(getContext(),"0DUEIIn35xtmfWC2DXprK5kqNF-aEaNgRJ4ONxw");

    //Change Your Map Key Here.....
    mapView = new MapView(getContext(),"0YOGrMpIJgaO92C0lXFtI6qF5YRl2Oe5h9UVoiQ");
    mapView.setEnabled(true);
    mapView.setClickable(true);
    addView(v);

    addView(mapView);

    overlay = new MapLocationOverlay(this);
    mapView.getOverlays().add(overlay);

    mapView.getController().setZoom(14);
    //mapView.setSatellite(true);
    mapView.getController().setCenter(getMapLocations().get(0).getPoint());
}
 }
Manmohan Badaya
  • 2,326
  • 1
  • 22
  • 35

2 Answers2

0

Use

mapview.requestLayout() or mapview.invalidate(). 

This will eventually cause a redraw.

Rakesh Bhalani
  • 668
  • 4
  • 10
0

You have problem with inflating the xml layout try to look in the Binary XML file line #6: Error inflating class <unknown> it seems the activity cannot find your custom view which is your MapLocationViewer.

Try to close the tag properly.

<com.app.milesoft.map.multipleusers.MapLocationViewer
     android:id="@+id/map_location_viewer"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" />

Check also if your MapLocationViewer is in correct package as you have provided in the xml tag which is com.app.milesoft.map.multipleusers.

Ariel Magbanua
  • 3,083
  • 7
  • 37
  • 48
  • I am facing troublw while i am doing this twice first time it is working like a charm.and during posting the code i missed the closind part of node in xml.as i told u in post i did by closing and again starting..the problem u are saying if their then it must be not single time but it is working and MapLocationViewer present at stated in xml. – Manmohan Badaya Mar 07 '13 at 12:37