3

I implemented a map method using the Google Maps API. Yesterday, it was working fine. Since then, I've made absolutely no changes whatsoever to eclipse, any map related method (including views and the MapActivity class) or anything in the its corresponding entry in the manifest - the only thing I changed was to add a splash screen, thereby changing the launcher activity from MyLITactivity to SplashActivity.

My API key is in the manifest, and I've included the uses-library entry in the manifest.

When I run the app, logcat shows this:

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

My manifest:

<?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));        
    }

}

If I comment out the OnMapClickListener and OnMapLongClickListener implements (and their corresponding methods) the error disappears.

1 Answer 1

4

Solved: I removed and re-imported all libraries, fixed project properties and did a clean-build.

Still have no idea why it worked yesterday and not today...

1
  • Just the same with you.
    – Owen Zhao
    Aug 2, 2013 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.