开发者

MapView: Could not find class A referenced from method B

开发者 https://www.devze.com 2023-03-16 03:43 出处:网络
There are 3 buttons on the screen! Start, View Map, Stop When I click View Map, it should go to a new screen that shows the map! But something goes wrong and the app is getting force closed! I keep g

There are 3 buttons on the screen! Start, View Map, Stop

When I click View Map, it should go to a new screen that shows the map! But something goes wrong and the app is getting force closed! I keep getting Could not find class A referenced from method B error. Please please please someone correct it. I've been struck with this for 3 days!!! :'(

Main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<TextView 
    android:text="GPS App"
    android:id="@+id/textView1"
    android:textSize="40sp"   
    android:padding="10dp"
    android:gravity="center"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"   
    />

<Button 
    android:text="Start" 
    android:id="@+id/buttonStart"
    android:textSize="30sp" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent"  
    />

<Button 
    android:text="View Map" 
    android:id="@+id/buttonMap" 
    android:textSize="30sp" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    />

<Button 
    android:text="Stop" 
    android:id="@+id/buttonStop" 
    android:textSize="30sp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    />

</LinearLayout>

map.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mymap"
    android:clickable="true"
    android:enabled="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:apiKey="xxxxxxxxxxxxx" 
    />

<LinearLayout
    android:id="@+id/myzoom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    />

</RelativeLayout>

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Firstdroid.Gps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:permission="android.permission.INTERNET" 
android:name=".IntentService" android:enabled="true" />
<activity android:name=".MapViewer" android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

MainActivity.java

package Firstdroid.Gps;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity 
{
    /** Called when the activity is first created. */
   @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /* START BUTTON */开发者_如何转开发

        Button startButton = (Button) findViewById(R.id.buttonStart);
        startButton.setOnClickListener(new OnClickListener() 
        {
                @Override
                public void onClick(View arg0) 
                {
                Log.d("Firstdroid.Gps", "Starting Exploration..");
                // Start Exploration
                startService(new Intent(MainActivity.this, GPSexp.class));
                }
        });

        /* MAP BUTTON */

        Button mapButton = (Button) findViewById(R.id.buttonMap);
        mapButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v){
                    Log.d("Firstdroid.Gps", "Loading Map..");
                    // Loading Google Map View
                    startService(new Intent(MainActivity.this, MapViewer.class));
                }       
        });

        /* STOP BUTTON */

        Button stopButton = (Button) findViewById(R.id.buttonStop);
        stopButton.setOnClickListener(new OnClickListener() 
        {
                @Override
                public void onClick(View v) 
                {
                Log.d("Firstdroid.Gps", "Stopping Exploration..");
                // Stop Exploration
                stopService(new Intent(MainActivity.this, GPSexp.class));
        }
        });
    }
}/* End of MainActivity */

The start and stop buttons refer to GPSexp.class defined in GPSexp.java which works correctly. Problem is with MapViewer.java

MapViewer.java

package Firstdroid.Gps;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
public class MapViewer extends MapActivity {

    MapView myMap;
    MyLocationOverlay myLocOverlay;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);

        initMap();
        initMyLocation();
    }

    private void initMap() {
        myMap = (MapView) findViewById(R.id.mymap);

        View zoomView = myMap.getZoomControls();
        LinearLayout myzoom = (LinearLayout) findViewById(R.id.myzoom);
        myzoom.addView(zoomView);
        myMap.displayZoomControls(true);

    }

    /**
     * Initialises the MyLocationOverlay and adds it to the overlays of the map
     */
    private void initMyLocation() {
        myLocOverlay = new MyLocationOverlay(this, myMap);
        myLocOverlay.enableMyLocation();
        myMap.getOverlays().add(myLocOverlay);

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

Logcat

06-30 04:25:07.519: WARN/dalvikvm(357): Unable to resolve superclass of LFirstdroid/Gps/MapViewer; (37)
06-30 04:25:07.519: WARN/dalvikvm(357): Link of class 'LFirstdroid/Gps/MapViewer;' failed
06-30 04:25:07.547: ERROR/dalvikvm(357): Could not find class 'Firstdroid.Gps.MapViewer', referenced from method Firstdroid.Gps.MainActivity$2.onClick
06-30 04:25:07.547: WARN/dalvikvm(357): VFY: unable to resolve const-class 8 (LFirstdroid/Gps/MapViewer;) in LFirstdroid/Gps/MainActivity$2;
06-30 04:25:07.559: DEBUG/dalvikvm(357): VFY: replacing opcode 0x1c at 0x000d
06-30 04:25:07.573: DEBUG/dalvikvm(357): VFY: dead code 0x000f-0015 in LFirstdroid/Gps/MainActivity$2;.onClick (Landroid/view/View;)V
06-30 04:25:07.909: INFO/ActivityManager(58): Displayed activity Firstdroid.Gps/.MainActivity: 1828 ms (total 1828 ms)
06-30 04:25:13.180: DEBUG/dalvikvm(129): GC_EXPLICIT freed 670 objects / 38560 bytes in 169ms
06-30 04:25:13.840: DEBUG/Firstdroid.Gps(357): Loading Map..
06-30 04:25:13.850: DEBUG/AndroidRuntime(357): Shutting down VM
06-30 04:25:13.850: WARN/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-30 04:25:13.880: ERROR/AndroidRuntime(357): FATAL EXCEPTION: main
06-30 04:25:13.880: ERROR/AndroidRuntime(357): java.lang.NoClassDefFoundError: Firstdroid.Gps.MapViewer
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at Firstdroid.Gps.MainActivity$2.onClick(MainActivity.java:40)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at android.view.View.performClick(View.java:2408)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at android.view.View$PerformClick.run(View.java:8816)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at android.os.Handler.handleCallback(Handler.java:587)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at android.os.Looper.loop(Looper.java:123)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at java.lang.reflect.Method.invokeNative(Native Method)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at java.lang.reflect.Method.invoke(Method.java:521)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-30 04:25:13.880: ERROR/AndroidRuntime(357):     at dalvik.system.NativeStart.main(Native Method)
06-30 04:25:13.900: WARN/ActivityManager(58):   Force finishing activity Firstdroid.Gps/.MainActivity
06-30 04:25:14.450: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44fe90c0 Firstdroid.Gps/.MainActivity}
06-30 04:25:15.750: INFO/Process(357): Sending signal. PID: 357 SIG: 9
06-30 04:25:15.841: INFO/ActivityManager(58): Process Firstdroid.Gps (pid 357) has died.
06-30 04:25:15.880: INFO/WindowManager(58): WIN DEATH: Window{4500c988 Firstdroid.Gps/Firstdroid.Gps.MainActivity paused=false}


You added uses-library as child of the activity element... maybe that's the problem.

This is not a standard package in the Android library. In order to use it, you must add the following XML element, as a child of the application element, in your AndroidManifest.xml file:

<uses-library android:name="com.google.android.maps" />


You're using startService to start your MapViewer activity. Hope that helps

0

精彩评论

暂无评论...
验证码 换一张
取 消