Android Maps API:无法解析的界面
作者:互联网
我使用Google Maps API实现了一种地图方法.昨天工作正常.从那时起,我完全没有对Eclipse进行任何更改,任何与地图相关的方法(包括视图和MapActivity类)或清单中其对应条目中的任何内容-我所做的唯一更改就是添加了一个初始屏幕,从而将启动器活动从MyLITactivity更改为SplashActivity.
我的API密钥在清单中,并且清单中包含了uses-library条目.
当我运行应用程序时,logcat会显示以下内容:
05-06 16:12:04.855: I/dalvikvm(753): Failed resolving Lcom/mad/mylit/MapActivity; interface 486 'Lcom/google/android/gms/maps/GoogleMap$OnMapClickListener;'
05-06 16:12:04.855: W/dalvikvm(753): Link of class 'Lcom/mad/mylit/MapActivity;' failed
05-06 16:12:04.855: E/dalvikvm(753): Could not find class 'com.mad.mylit.MapActivity', referenced from method com.mad.mylit.MyLITactivity.startMaps
05-06 16:12:04.855: W/dalvikvm(753): VFY: unable to resolve const-class 495 (Lcom/mad/mylit/MapActivity;) in Lcom/mad/mylit/MyLITactivity;
05-06 16:12:04.855: D/dalvikvm(753): VFY: replacing opcode 0x1c at 0x0002
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mad.mylit"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/lit_logo"
android:label="@string/app_name"
android:theme="@style/Theme.litac" >
<activity
android:name="com.mad.mylit.MyLITactivity"
android:label="@string/app_name"
android:theme="@style/Theme.litac" >
</activity>
<activity
android:name="com.mad.mylit.ItemListActivity"
android:label="@string/title_item_list" >
</activity>
<activity
android:name="com.mad.mylit.ItemDetailActivity"
android:label="@string/title_item_detail"
android:parentActivityName=".ItemListActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ItemListActivity" />
</activity>
<activity
android:name="com.mad.mylit.NewsDetailFragment"
android:label="@string/title_activity_news_detail_fragment" >
</activity>
<activity
android:name="com.mad.mylit.NewsListFragment"
android:label="@string/title_activity_news_list_fragment" >
</activity>
<activity
android:name="com.mad.mylit.NewsActivity"
android:label="@string/title_activity_news" >
</activity>
<activity
android:name="com.mad.mylit.DetailActivity"
android:label="SU News" >
</activity>
<activity
android:name="com.mad.mylit.TimetableActivity"
android:label="@string/title_activity_timetable" >
</activity>
<activity
android:name="com.mad.mylit.MoodleActivity"
android:label="@string/title_activity_moodle" >
</activity>
<activity
android:name="com.mad.mylit.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxx" />
<activity
android:name="com.mad.mylit.MapActivity"
android:label="@string/title_activity_map"
android:parentActivityName="com.mad.mylit.MyLITactivity" >
android:theme="@style/Theme.litac"
android:uiOptions="splitActionBarWhenNarrow" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mad.mylit.MyLITactivity" />
</activity>
</application>
</manifest>
MapActivity:
public class MapActivity extends FragmentActivity implements OnMapClickListener, OnMapLongClickListener{
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
Location myLocation;
LocationManager locationManager;
String provider;
OnLocationChangedListener myLocationListener = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setupActionBar();
android.support.v4.app.FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
myMap.setOnMapClickListener(this);
myMap.setOnMapLongClickListener(this);
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
}
public void activate(OnLocationChangedListener listener) {
myLocationListener = listener;
}
public void deactivate() {
myLocationListener = null;
}
private void setupActionBar() {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.maps, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.menu_legalnotices:
String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(
getApplicationContext());
AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MapActivity.this);
LicenseDialog.setTitle("Legal Notices");
LicenseDialog.setMessage(LicenseInfo);
LicenseDialog.show();
return true;
case R.id.itemid_1:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=Limerick Institute of Technology, Limerick"));
startActivity(i);
return true;
case R.id.itemid_2:
//TODO change to local map of LIT
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
public void onLocationChanged(Location location) {
myLocationListener.onLocationChanged(location);
LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());
myMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onMapLongClick(LatLng point) {
//myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
}
@Override
public void onMapClick(LatLng point) {
//myMap.animateCamera(CameraUpdateFactory.newLatLng(point));
}
}
如果我注释掉OnMapClickListener和OnMapLongClickListener实现(及其对应的方法),则错误消失.
解决方法:
解决:我删除并重新导入了所有库,修复了项目属性,并进行了干净构建.
仍然不知道为什么它昨天而不是今天起作用了…
标签:eclipse,android,google-maps-api-2 来源: https://codeday.me/bug/20191030/1971699.html