问题描述
我试图让谷歌地图活动找到旅行距离。但不幸的是,layout.xml文件丢失,下面的错误和停止的应用程序。我使用Min SDK版本 - 16.我尝试了很多事情,但仍然错误仍然存在。我在真实设备上运行我的应用程序。期待一些专家的帮助。
2218 /? E / AndroidRuntime:FATAL EXCEPTION:main
java.lang.RuntimeException:无法启动活动ComponentInfo {scpp.globaleye.com.scppclient / scpp.globaleye.com.scppclient.ui.MapsActivity}:android.view.InflateException :二进制XML文件行#8:错误膨胀类的片段
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access $ 600(ActivityThread.java:149)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1300)
at android.os。 Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:821)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
在dalvik.system.NativeStart.main(本地方法)
导致:android.view.InflateException:二进制XML文件行#8:在android.view.LayoutInflater.createView中膨胀类片段
时出错FromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow .setContentView(PhoneWindow.java:258)
at android.app.Activity.setContentView(Activity.java:1867)
at scpp.globaleye.com.scppclient.ui.MapsActivity.onCreate(MapsActivity.java :44)
at android.app.Activity.performCreate( Activity.java:5020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android .app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access $ 600(ActivityThread.java:149)
at android.app.ActivityThread $ H.handleMessage(ActivityThread。 java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app .ActivityThread.main(ActivityThread.ja va:4987)
在java.lang.reflect.Method.invokeNative(本地方法)$ b $在java.lang.reflect.Method.invoke(Method.java:511)
at com。 android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system。 NativeStart.main(本地方法)
引起:java.lang.NullPointerException
在com.google.maps.api.android.lib6.gmm6.m.ad.a(未知源)
在com.google.maps.api.android.lib6.gmm6.cha(未知来源)
at co m.google.maps.api.android.lib6.gmm6.cya(未知来源)
,位于com.google.maps.api.android.lib6.e.bd.a(未知来源)
at com.google.maps.api.android.lib6.e.e.(不明来源)
在com.google.maps.api.android.lib6.eza(未知来源)
at com。 google.maps.api.android.lib6.eya(未知来源)
at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
at android.os.Binder .transact(Binder.java:326)
在com.google.android.gms.maps.internal.IMapFragmentDelegate $ zza $ zza.onCreateView(未知源代码)
在com.google.android.gms。 maps.MapFragment $ ZZA .onCreateView(未知来源)
在com.google.android.gms.dynamic.zza $ 4.zzb(未知来源)
在com.google.android.gms.dynamic.zza.zza(未知来源)
在com.google.android.gms.dynamic.zza.onCreateView(未知来源)
来自com.google.android.gms.maps.MapFragment.onCreateView(未知来源)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java: 1112)
在android.app.Activity.onCreateView(Activit y.java:4676)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java: 79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater .inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
在com.and roid.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:258)
at android.app.Activity.setContentView(Activity.java:1867)
at scpp.globaleye.com.scppclient。 ui.MapsActivity.onCreate(MapsActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access $ 600(ActivityThread.java:149)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper .java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)$ b $ at java.lang .reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os .ZygoteInit.main(ZygoteInit.java:584)
at dalvik.syst em.NativeStart.main(本地方法)
我的 MapsActivity 类。我评论其他行并找到 setContentView(R.layout.activity_maps);
传递此错误并停止应用程序。
public class MapsActivity extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
double start_lat,stop_lat,start_lng,stop_lng,lat,lng;
标准标准;
LocationManager locationManager;
字符串提供程序;
位置位置;
按钮start_btn,stop_btn;
TextView电视;
float [] distance = new float [1];
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// MapFragment fm =(MapFragment)getFragmentManager()。findFragmentById(R.id.map);
//System.out.println(\"on createteeeeeeeeeeeeeeeee);
// SupportMapFragment fm =(SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.map);
/ * googleMap = fm.getMap();
getLocation();
////// button
start_btn =(Button)findViewById(R.id.button1);
stop_btn =(Button)findViewById(R.id.button2);
stop_btn.setEnabled(false);
start_btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//单击
执行操作// System.out .println(startttttttttttttttttttttttttbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
if(tv!= null){
tv.setText();
}
stop_btn.setEnabled(true );
start_btn.setEnabled(false);
getStarrtLoc(location);
}
});
stop_btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//点击
//System.out .println(stopppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppbbbbbbbbbbbbb);
start_btn.setEnabled(true);
stop_btn.setEnabled(false);
getStoptLoc(location);
}
}) ; * /
}
@Override
public void onLocationChanged(Location loc){
location = loc;
//System.out.println(\"changgggggggggggggggggggggg+\"+loc.getLatitude()+ loc.getLongitude());
}
@Override
public void onProviderDisabled(String provider){
// TODO自动生成的方法存根
}
@Override
public void onProviderEnabled(String provider){
// TODO自动生成的方法存根
}
@Override
public void onStatusChanged (String provider,int status,Bundle extras){
// TODO自动生成方法存根
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
返回true;
$ b $ public Location getLocation(){
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED&&& ActivityCompat.checkSelfPermission(这个,Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
// return;
Toast.makeText(this,NO PERMISSION,Toast.LENGTH_LONG).show();
}
//启用Google地图的MyLocation图层
googleMap.setMyLocationEnabled(true);
//从系统服务LOCATION_SERVICE获取LocationManager对象$ b $ locationManager =(LocationManager)getSystemService(LOCATION_SERVICE);
//创建一个标准对象来检索提供者
criteria = new Criteria();
//获取最佳供应商的名称
provider = locationManager.getBestProvider(criteria,true);
$ b $ //获取当前位置
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED&&& ActivityCompat.checkSelfPermission(this,Manifest.permission。 ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
// return;
Toast.makeText(this,NO PERMISSION,Toast.LENGTH_LONG).show();
}
location = locationManager.getLastKnownLocation(provider);
if(location!= null){
Toast.makeText(this,GPS FIXED,Toast.LENGTH_LONG).show();
// onLocationChanged(location);
//返回位置;
lat = location.getLatitude();
ng = location.getLongitude();
}
locationManager.requestLocationUpdates(provider,0,0,this);
//System.out.println(\"lllllllllllllllllllllllllllllllllllllllll);
返回地点;
}
public void getStarrtLoc(Location start_loc){
start_lat = start_loc.getLatitude();
start_lng = start_loc.getLongitude();
//System.out.println(\"startttttttttttttttttttttttttttttttttt\"+start_lat+\"ffffffffff\"\" startstart_lng);
public void getStoptLoc(Location stop_loc){
stop_lat = stop_loc.getLatitude();
stop_lng = stop_loc.getLongitude();
//System.out.println(\"stpppppppppppppppppppppppppppppppppppp\"\"startup_lat+\"ffffffffff\"+stop_lng);
calcDistance();
tv =(TextView)findViewById(R.id.textView);
tv.setText(Distance:+ distance [0]);
//System.out.println(\"dddddddddd\"\"ddistance[0]);
public void calcDistance(){
Location.distanceBetween(start_lat,start_lng,stop_lat,stop_lng,distance);
}
@Override
public void onBackPressed(){
super.onBackPressed();
Intent intent = new Intent(MapsActivity.this,UserSelect.class);
MapsActivity.this.startActivity(intent);
MapsActivity.this.finish();
我的 Activity_Map.xml file。
<?xml version =1.0encoding =utf-8?> < RelativeLayout xmlns:android =http://schemas.android.com/apk/res/android
xmlns:tools =http://schemas.android.com/tools
android :layout_width =match_parent
android:layout_height =match_parent
tools:context =。ui.MapsActivity>
<片段
xmlns:map =http://schemas.android.com/apk/res-auto
android:name =com.google.android .gms.maps.MapFragment
android:id =@ + id / map
android:layout_width =match_parent
android:layout_height =match_parent
android: layout_above =@ + id / layout1
tools:layout =@ layout / activity_maps/>
< RelativeLayout
android:orientation =vertical
android:layout_width =match_parent
android:layout_height =70dp
android: id =@ + id / layout1
android:layout_alignParentLeft =true
android:layout_alignParentStart =true
android:layout_alignParentBottom =true>
android:layout_width =145dp
android:layout_height =70dp
android:text =Start Ride
android :id =@ + id / button1
android:layout_alignParentLeft =true/>
< Button
android:layout_width =145dp
android:layout_height =70dp
android:text =Stop Ride
android :id =@ + id / button2
android:layout_alignParentRight =true/>
< TextView
android:layout_width =wrap_content
android:layout_height =70dp
android:text =
android:id =@ + id / textView
android:layout_toLeftOf =@ + id / button2
android:layout_toRightOf =@ + id / button1
android:layout_toStartOf =@ id / button2
android:layout_toEndOf =@ + id / button1/>
< / RelativeLayout>
< / RelativeLayout>
我的androidMainfest.xml
<?xml version =1.0encoding =utf-8?>
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =scpp.globaleye.com.scppclient>
< uses-sdk
android:minSdkVersion =16
/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.INTERNET/>
<使用权限android:name =android.permission.CAMERA/>
< uses-permission android:name =android.permission.RECEIVE_BOOT_COMPLETED/>
<! - 用于缓存的外部存储 - >
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
使用
Google地图Android API v2时不需要ACCESS_COARSE / FINE_LOCATION权限,但您必须指定粗略或精细的
位置'MyLocation'功能的权限。
- >
< uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/>
< uses-permission android:name =android.permission.ACCESS_COARSE_LOCATION/>
$应用程序
android:allowBackup =true
android:icon =@ mipmap / ic_launcher
android: label =@ string / app_name
android:supportsRtl =true
android:theme =@ style / AppTheme
>
Google Maps API API键被定义为字符串资源。
(请参阅文件res / values / google_maps_api.xml)。
请注意,API密钥已链接到用于签署APK的加密密钥。
您需要为每个加密密钥使用不同的API密钥,包括用于
签名的发布密钥。
您可以在src / debug /和src / release /中定义调试和发布目标的键。
- >
< meta-data
android:name =com.google.android.geo.API_KEY
android:value =AIzaSyBLN7wET4T0n6gu6Jr3AwE6jOQpqICkMBE/>
< service
android:name =。services.RemoteSenzService
android:enabled =true
android:exported =true><<<<< ; /服务>
< activity android:name =。ui.Login>
< intent-filter>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< activity android:name =。ui.Home/>
< activity android:name =。ui.Services_View/>
< activity android:name =。ui.Update_Profile/>
< activity android:name =。ui.UserSelect/>
< activity android:name =。ui.Wallet/>
< activity android:name =。ui.Registration/>
< activity
android:name =。ui.MapsActivity
android:label =@ string / title_activity_maps>
< / activity>
< / application>
< / manifest>
我认为这是因为您使用的是FragmentActivity,所以您应该使用SupportMapFragment而不是MapFragment(因为支持API Activity与支持库的Fragment类一起使用,而不与基础框架中的一个一起使用)。尝试更改此行
android:name =com.google.android.gms.maps.MapFragment
至此
android:name =com.google.android.gms.maps.SupportMapFragment
,需要注意的是你也应该使用AppCompatActivity而不是FragmentActivity。
I am trying to make Google Map activity to find travel distance.But Unfortunately layout.xml file throw , below error and stop app. I used Min SDK version - 16.I tried lot of thing to do but still error is remain.I run my app in real device.Expect some expert help.
2218/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{scpp.globaleye.com.scppclient/scpp.globaleye.com.scppclient.ui.MapsActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access$600(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:258)
at android.app.Activity.setContentView(Activity.java:1867)
at scpp.globaleye.com.scppclient.ui.MapsActivity.onCreate(MapsActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access$600(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.google.maps.api.android.lib6.gmm6.m.ad.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.y.a(Unknown Source)
at com.google.maps.api.android.lib6.e.bd.a(Unknown Source)
at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
at com.google.maps.api.android.lib6.e.z.a(Unknown Source)
at com.google.maps.api.android.lib6.e.y.a(Unknown Source)
at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment$zza.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
at android.app.Activity.onCreateView(Activity.java:4676)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:258)
at android.app.Activity.setContentView(Activity.java:1867)
at scpp.globaleye.com.scppclient.ui.MapsActivity.onCreate(MapsActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access$600(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
My MapsActivity class. I comment other line and find setContentView(R.layout.activity_maps);
pass this error and stop app.
public class MapsActivity extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
double start_lat,stop_lat,start_lng,stop_lng,lat,lng;
Criteria criteria;
LocationManager locationManager;
String provider;
Location location;
Button start_btn,stop_btn;
TextView tv;
float[] distance = new float[1];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
//MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
//System.out.println("on createteeeeeeeeeeeeeee");
//SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
/*googleMap = fm.getMap();
getLocation();
//////button
start_btn = (Button) findViewById(R.id.button1);
stop_btn = (Button) findViewById(R.id.button2);
stop_btn.setEnabled(false);
start_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
//System.out.println("startttttttttttttttttttttttttbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
if(tv != null){
tv.setText("");
}
stop_btn.setEnabled(true);
start_btn.setEnabled(false);
getStarrtLoc(location);
}
});
stop_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
//System.out.println("stoppppppppppppppppppppppppppbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
start_btn.setEnabled(true);
stop_btn.setEnabled(false);
getStoptLoc(location);
}
});*/
}
@Override
public void onLocationChanged(Location loc) {
location = loc;
//System.out.println("changggggggggggggggggggggggggg"+loc.getLatitude()+loc.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
public Location getLocation(){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//return;
Toast.makeText(this,"NO PERMISSION", Toast.LENGTH_LONG).show();
}
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
// Getting LocationManager object from System Service LOCATION_SERVICE
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
criteria = new Criteria();
// Getting the name of the best provider
provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//return;
Toast.makeText(this,"NO PERMISSION", Toast.LENGTH_LONG).show();
}
location = locationManager.getLastKnownLocation(provider);
if(location!=null){
Toast.makeText(this,"GPS FIXED", Toast.LENGTH_LONG).show();
//onLocationChanged(location);
//return location;
lat=location.getLatitude();
lng=location.getLongitude();
}
locationManager.requestLocationUpdates(provider,0,0, this);
//System.out.println("llllllllllllllllllllllllllllllllllllll"+lat+lng);
return location;
}
public void getStarrtLoc(Location start_loc){
start_lat = start_loc.getLatitude();
start_lng = start_loc.getLongitude();
//System.out.println("startttttttttttttttttttttttttttttttttt"+start_lat+"ffffffffff"+start_lng);
}
public void getStoptLoc(Location stop_loc){
stop_lat = stop_loc.getLatitude();
stop_lng = stop_loc.getLongitude();
//System.out.println("stppppppppppppppppppppppppppppppppppppp"+stop_lat+"ffffffffff"+stop_lng);
calcDistance();
tv = (TextView) findViewById(R.id.textView);
tv.setText("Distance :"+distance[0]);
//System.out.println("dddddddddd"+distance[0]);
}
public void calcDistance(){
Location.distanceBetween(start_lat,start_lng,stop_lat,stop_lng,distance);
}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(MapsActivity.this, UserSelect.class);
MapsActivity.this.startActivity(intent);
MapsActivity.this.finish();
}
}
My Activity_Map.xml file.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MapsActivity">
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layout1"
tools:layout="@layout/activity_maps" />
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="@+id/layout1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true">
<Button
android:layout_width="145dp"
android:layout_height="70dp"
android:text="Start Ride"
android:id="@+id/button1"
android:layout_alignParentLeft="true"/>
<Button
android:layout_width="145dp"
android:layout_height="70dp"
android:text="Stop Ride"
android:id="@+id/button2"
android:layout_alignParentRight="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="70dp"
android:text=""
android:id="@+id/textView"
android:layout_toLeftOf="@+id/button2"
android:layout_toRightOf="@+id/button1"
android:layout_toStartOf="@id/button2"
android:layout_toEndOf="@+id/button1" />
</RelativeLayout>
</RelativeLayout>
my androidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="scpp.globaleye.com.scppclient">
<uses-sdk
android:minSdkVersion="16"
/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<!-- To boot complete broadcast receiver -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- External storage for caching -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBLN7wET4T0n6gu6Jr3AwE6jOQpqICkMBE" />
<service
android:name=".services.RemoteSenzService"
android:enabled="true"
android:exported="true"></service>
<activity android:name=".ui.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.Home" />
<activity android:name=".ui.Services_View" />
<activity android:name=".ui.Update_Profile" />
<activity android:name=".ui.UserSelect" />
<activity android:name=".ui.Wallet" />
<activity android:name=".ui.Registration" />
<activity
android:name=".ui.MapsActivity"
android:label="@string/title_activity_maps">
</activity>
</application>
</manifest>
I think that is because you are using a FragmentActivity, so you should use the SupportMapFragment and not the MapFragment (Because the support API Activity works with the Fragment class of the support library and not with the one of the base framework). Try changing this line
android:name="com.google.android.gms.maps.MapFragment"
to this
android:name="com.google.android.gms.maps.SupportMapFragment"
As a side note, it's important to note that you should also use the AppCompatActivity instead of the FragmentActivity.
这篇关于android.view.InflateException:二进制XML文件行#8:错误膨胀类的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!