问题
I have a view with a facebook style side bar navigation. On the main view I want to display my map. I have followed Google's tutorial exactly! But I keep running into the error Unable to instantiate android.gms.maps.SupportMapFragment.
I did manage to run this on a plain project but when I merge it with my main project this error pops up:
07-25 13:27:53.778: E/AndroidRuntime(24841):
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment:
make sure class name exists, is public, and has an empty constructor that is public
I tried the answers posted below but the problem persists.
"Error inflating class fragment" with google map
and also this one:
Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2
The reference to the google sdk in project properties is also set. Here is the class:
public class SlideAnimationThenCallLayout extends FragmentActivity implements AnimationListener {
View menu;
View app;
boolean menuOut = false;
AnimParams animParams = new AnimParams();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slide_animation_then_call_layout);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.menu);
linearLayout.setOnTouchListener(new OnSwipeTouchListener(){
public void onSwipeRight() {
swipeAnimation();
}
});
RelativeLayout listview3 = (RelativeLayout) findViewById(R.id.relativeLayout1);
listview3.setOnTouchListener(new OnSwipeTouchListener(){
public void onSwipeRight() {
swipeAnimation();
}
public void onSwipeLeft() {
swipeAnimation();
}
});
menu = findViewById(R.id.menu);
app = findViewById(R.id.relativeLayout1);
}
The xml file is:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame_layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/action_eating">
</ListView>
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/android_homescreen">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
I don't know what is wrong here now. Any Help would be greatly appreciated.
回答1:
Judging by you error:
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
and the fact the SupportManFragment
class is part of the google-play-services
library, you problem is surtenly in the way you reference this library or the library it self.
I would suggest you to re-download it using the SDK-Manager and move it to a location where it path would be shorter and then try to reference it again using the answer you have in this question:
Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2
回答2:
Right click on project ---> Android Tools ---> Add Support Library. Download it and clear the project and build again. Hope it will work
来源:https://stackoverflow.com/questions/17853027/unable-to-instantiate-android-gms-maps-supportmapfragment