当从Android API的location manager类调用方法时,会不断出现以下警告。我使用的是最新的Android Studio2.1,目标操作系统是Android4.0.3或以上。那有什么不好?提前道谢!
>
I/DalvikVM:找不到方法Android.Content.Context.GetSystemService(从方法引用)MainActivity$GPSService.Access$Super
w/dalvikvm:vfy:无法解析虚拟方法514:landroid/content/context;.getColorStateList(I)landroid/content/res/ColorStateList;
d/dalvikvm:vfy:在0x004f处替换操作码0x6f i/dalvikvm:找不到方法Android.content.contextWrapper.GetCodeCacheDir,从方法引用
w/dalvikvm:vfy:无法解析虚拟方法585:landroid/content/contextwrapper;.getCodeCachedir()ljava/io/file;
D/DALVIKVM:VFY:将操作码0x6F替换为0x00E1
I/DalVikVM:找不到方法Android.content.contextWrapper.GetNoBackupFilesDir(从方法引用)
w/dalvikvm:vfy:无法解析虚拟方法597:landroid/content/contextwrapper;.getnobackupfilesdir()ljava/io/file;
I/DalvikVM:找不到方法Android.content.context.GetDrawable,从方法引用
w/dalvikvm:vfy:无法解析虚拟方法516:Landroid/Content/Context;.GetDrawable(I)Landroid/Graphics/Drawable/Drawable;
D/DALVIKVM:VFY:替换0x0317处的操作码0x6F
D/DALVIKVM:VFY:将操作码0x6F替换为0x03C6
I/DalvikVM:找不到方法Android.Content.ContextWrapper.GetExternalMediadirs,从方法引用
w/dalvikvm:vfy:无法解析虚拟方法593:landroid/content/contextwrapper;.getExternalMediadirs()[ljava/io/file;
D/DALVIKVM:VFY:替换0x0534处的操作码0x6F
I/DalvikVM:找不到方法Android.Content.ContextWrapper.CheckSelfPermission,从方法引用
w/dalvikvm:vfy:无法解析虚拟方法561:landroid/content/contextwrapper;.checkselfpermission(ljava/lang/string;)I
public static class GPSService extends Service implements android.location.LocationListener{
MainActivity ma = new MainActivity();
private ScheduledExecutorService scheduleTaskExecutor;
private ScheduledFuture scheduledFuture=null;
private Context sContext = GPSService.this;
private String deviceId;
//= loadStr(getContext(), "deviceId");
final static String TAG = "GPSService";
// flag for GPS status
boolean isGPSEnabled = false;
// flag for network status
boolean isNetworkEnabled = false;
// flag for GPS status
boolean canGetLocation = false;
Location location; // location
double latitude; // latitude
double longitude; // longitude
// Declaring a Location Manager
protected LocationManager locationManager;
public GPSService() {
super();
}
public Context getContext() {
return sContext;
}
public Location getLocation() {
try {
/*
locationManager = (LocationManager) sContext
.getSystemService(LOCATION_SERVICE);*/
// getting GPS status
/*
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
2000,
10, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
2000,
10, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}else {
showSettingsAlert();
}
}*/
}catch (SecurityException e){
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
return location;
}
public void stopUsingGPS(){
try{
if(locationManager != null){
locationManager.removeUpdates(GPSService.this);
}
}catch (SecurityException e){
e.printStackTrace();
}
}
public double getLatitude(){
if(location != null){
latitude = location.getLatitude();
}
return latitude;
}
public double getLongitude(){
if(location != null){
longitude = location.getLongitude();
}
return longitude;
}
public boolean canGetLocation() {
return this.canGetLocation;
}
public void showSettingsAlert(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(sContext);
alertDialog.setTitle("GPS");
alertDialog.setMessage("GPS setting");
alertDialog.setPositiveButton("setting", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
sContext.startActivity(intent);
}
});
alertDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
//--------------------------------------------------------------
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
//------------------------------------------------------------
@Override
public void onCreate() {
super.onCreate();
Log.d("service","on create");
//getLocation();
try {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 2000, 10, this);
}catch(SecurityException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.d("service","on start cmd");
Bundle extras = intent.getExtras();
if(extras == null){
this.deviceId=null;
Log.d("Service passed id","null");}
else
{
this.deviceId = (String) extras.get("deviceId");
Log.d("passed id",deviceId);
}
scheduleTaskExecutor= Executors.newScheduledThreadPool(5);
scheduledFuture = scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
public void run() {
Log.d("inside on Start Cmd","running thread");
try{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} catch(SecurityException e){
e.printStackTrace();
}
}
}, 0, 10, TimeUnit.SECONDS);
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
if (scheduledFuture!=null){
scheduledFuture.cancel(false);
Log.d("service" , "on destroy scheduled future");
}
if (locationManager!=null)
stopUsingGPS();
Log.d("service" , "on destroy");
}
}
抱歉,最后我自己搞定了。都是因为我的愚蠢错误。location manager方法应该按如下方式分组tgt。
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 2000, 10, this);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
我试图通过OnConnect方法中的location客户端请求位置更新。我的片段实现了LocationListener,GooglePlayServicesClient。ConnectionCallbacks和GooglePlayServicesClient。OnConnectionFailedListener。 代码看起来像这样。 错误是“找不到适用于requestLocationUpdates
方法fragmentTransaction.add(Fragment,String)不适用(实际参数int无法通过方法调用转换转换为Fragment) 我的代码的一部分:
在规范中,我想模拟类: b)我可以在文档中找到关于为什么要为存根或模拟调用原始类方法的信息?
如何解决此错误?我在这段代码中遇到了一个错误: 无法解决方法的add(int,android.trey.startingpoint.nl.秒活动。碎片 谢谢你的帮助! 编辑:导入: 导入android。应用程序。活动导入android。支持v4。应用程序。碎片 导入android。操作系统。捆导入android。看法更平坦;导入android。看法菜单导入android。看法MenuItem;导入
设置如下: 请求的时候也是统一了权限的。但是经纬度就是返回5e-324这种异常的
所以,基本上我创建了一个包装器类,它创建了一个简单的OpenGL应用程序。我的想法是在准备好的时候有这样的东西: 所以,基本上这个类使用GLFW封装了一个简单的OpenGL窗口。这个想法是,当你想要创建一个新的应用程序时,你只需要从应用程序类(我正在写的)派生你的类。使用这个新类,您只需重写虚拟方法(main Loop、初始化和回调),您将拥有一个工作应用程序。 下面是基类: 所以我所做的是将在派