Java 应用程序停止工作-片段布局-谷歌地图API v2
我看到了很多关于堆栈溢出的问题,没有答案解决了我的问题,我试图为片段设置一个布局,应用程序一次又一次地停止工作,我尝试了太多不同的模板,使片段处于相对布局,并且在没有相对布局的情况下独立运行,除了停止之外什么都没有发生Java 应用程序停止工作-片段布局-谷歌地图API v2,java,android,xml,google-maps,android-fragments,Java,Android,Xml,Google Maps,Android Fragments,我看到了很多关于堆栈溢出的问题,没有答案解决了我的问题,我试图为片段设置一个布局,应用程序一次又一次地停止工作,我尝试了太多不同的模板,使片段处于相对布局,并且在没有相对布局的情况下独立运行,除了停止之外什么都没有发生 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="ht
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
这是我的java代码,当我散列地图代码时,应用程序也会停止,我相信它在布局中
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (map!=null){
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
}
}
}
由于您的问题不清楚,请发布日志。
一个可能的错误是=>您正在使用哪个扩展。尝试使用您的手机中是否有google play服务?是的,我的手机中有google play服务。在您的应用程序日志中过滤日志,并发布您的片段代码。如何过滤日志?!我过滤只是为了得到错误,我无法理解,它一直在运行,显示许多不同的错误和警告。错误日志没有意义,哪里是异常。请清理并构建您的项目。我无法理解logCat,但我发布了它。@Neeraj Kumar它应该与MapFragment一起使用,而且两者都是相同的,除非您计划支持在api 11上运行的手机,无需使用SupportMapFragment()
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (map!=null){
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
}
}
}