无法实例化android.gms.maps.SupportMapFragment
我有一个facebook风格的侧栏导航视图。在主视图上,我想显示我的地图。我完全遵循了谷歌的教程!但我一直遇到无法实例化android.gms.maps.SupportMapFragment的错误 我确实设法在一个普通项目上运行了它,但当我将其与主项目合并时,会弹出以下错误:无法实例化android.gms.maps.SupportMapFragment,android,google-maps,android-fragments,android-maps-v2,Android,Google Maps,Android Fragments,Android Maps V2,我有一个facebook风格的侧栏导航视图。在主视图上,我想显示我的地图。我完全遵循了谷歌的教程!但我一直遇到无法实例化android.gms.maps.SupportMapFragment的错误 我确实设法在一个普通项目上运行了它,但当我将其与主项目合并时,会弹出以下错误: 07-25 13:27:53.778: E/AndroidRuntime(24841): Caused by: android.support.v4.app.Fragment$InstantiationException
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
我尝试了下面发布的答案,但问题仍然存在
还有这个:
还设置了在项目属性中对google sdk的引用。
下面是课堂:
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);
}
xml文件是:
<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>
我不知道现在这里出了什么问题。任何帮助都将不胜感激。右键单击project-->Android工具-->添加支持库。
下载它并清除项目,然后重新构建。希望它能工作从您的错误判断:
原因:android.support.v4.app.Fragment$实例化异常:无法实例化Fragment com.google.android.gms.maps.SupportMapFragment: 确保类名存在,是公共的,并且有一个公共的空构造函数 事实上,
SupportManFragment
类是googleplayservices
库的一部分,你的问题显然在于你引用这个库或它本身的库的方式
我建议您使用SDK管理器重新下载它,并将其移动到其路径较短的位置,然后尝试使用此问题中的答案再次引用它:
成功了!刚刚删除了旧的谷歌播放项目,并再次导入!非常感谢!:)无法实例化片段com.google.android.gms.maps.MapFragment:请确保类名存在、为public并且具有一个为public的空构造函数