使用MapView类的ClassNotFoundException抛出该异常 [英] ClassNotFoundException Thrown using MapView

查看:140
本文介绍了使用MapView类的ClassNotFoundException抛出该异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与寻找之所以这样code锁定挣扎。据我所知,我宣布我的清单文件的正确权限,如下图所示。我试图在实际设备上运行它(Droid X的瓦特/ 2.3.3)和AVD无济于事。我已经把它贴在logcat的以及它把我带到了ClassNotFound的异常。我已清理项目,并验证了maps.jar包含在googleapi的包,我也用作为目标应用程序。 (谷歌API的2.3.3)。不知道在哪里,从这里走。

 活动code:'包com.SmartPark;进口的java.util.List;进口android.content.Context;
进口android.graphics.drawable.Drawable;
进口android.location.Location;
进口android.location.LocationListener;
进口android.location.LocationManager;
进口android.os.Bundle;
进口android.os.Handler;
进口android.widget.LinearLayout;
//进口android.widget.TextView;
进口android.widget.Toast;进口com.google.android.maps.GeoPoint;
进口com.google.android.maps.MapActivity;
进口com.google.android.maps.MapView;
进口com.google.android.maps.Overlay;
进口com.google.android.maps.OverlayItem;公共类SmartParkActivity扩展MapActivity {
 // **当第一次创建活动调用。 * /
    LinearLayout中的LinearLayout;
    MapView类MapView类;
    清单<&叠加GT; mapOverlays;
    可绘制可绘制;
    HelloItemizedOverlay itemizedOverlay;
    的GeoPoint点=新的GeoPoint(42392400,-83134700);
    OverlayItem overlayitem =新OverlayItem(点,,);
    私人的LocationManager流明;
    私人LocationListener的LocationListener的;
    市民双[] = GPS新的双[2];
    公共布尔setgps;
    最后的处理程序mHandler =新的处理程序();
    // TextView的电视线; //纬度显示
   // TextView的tvlong; //显示经度
    INT LAT2;
    INT longitude2;
    公众持股量Z者除外;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        图形页面=(图形页面)findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(真);
        mapOverlays =调用MapView.getOverlays();
        绘制= this.getResources()getDrawable(R.drawable.greendot1)。
        itemizedOverlay =新HelloItemizedOverlay(绘制);
        OverlayItem overlayitem =新OverlayItem(点,,);
        itemizedOverlay.addOverlay(overlayitem);
       mapOverlays.add(itemizedOverlay);
       // TVL =(TextView中)this.findViewById(R.id.gpslview);
      // tvlong =(TextView中)this.findViewById(R.id.gpslongview);
    }    @覆盖
    保护布尔isRouteDisplayed(){            返回false;
    }     @覆盖
        保护无效调用onStart(){
            super.onStart();
        LM =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);        LocationListener的=新MyLocationListener();        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,100,0,
                LocationListener的);        mHandler.postDelayed(mUpdateTimeTask,500);    }
    @覆盖
    保护无效的onStop(){
        super.onStop();       lm.removeUpdates(LocationListener的);
        mHandler.removeCallbacks(mUpdateTimeTask);
        }    @覆盖
    保护无效的onDestroy(){
        super.onDestroy();       lm.removeUpdates(LocationListener的);
        mHandler.removeCallbacks(mUpdateTimeTask);
        }
    //}
 //辅助方法,安排在指定的时间间隔的postdelayed mhandler
    私人布尔富(){
        setgps = FALSE;
        mHandler.postDelayed(mUpdateTimeTask,500);        返回true;
    };
    //方法来获取一套GPS变量并显示它。更新覆盖如果可能的话
    私人Runnable接口mUpdateTimeTask =新的Runnable(){
           公共无效的run(){               mapOverlays.clear();
               的GeoPoint点= setgeopoint(GPS [0],GPS [1]);
               OverlayItem overlayitem =新OverlayItem(点,,);
               mapOverlays.add(itemizedOverlay);
               itemizedOverlay.addOverlay(overlayitem);              // tvl.setText(纬度:+ GPS [0]);
               // tvlong.setText(经度+ GPS [1]);
                 // Z =(浮点)android.location.Location.getSpeed​​();
                 setgps = foo的(); //重新安排任务    };
    };    //数学函数   //将GPS双为int并设置为GeoPoint的
    公众的GeoPoint setgeopoint(双升,​​双dlong){
        INT国际=(INT)(DL * 1000000);
        INT intlong =(INT)(dlong * 1000000);        的GeoPoint点=新的GeoPoint(国际,intlong);
        返回点;
    }
    公共类MyLocationListener实现LocationListener的
    {
        @覆盖
        公共无效onLocationChanged(位置LOC)
        {
            如果(LOC!= NULL){
                Toast.makeText(
                        getBaseContext(),
                        位置改变:纬度:+ loc.getLatitude()
                                +LNG:+ loc.getLongitude(),
                        Toast.LENGTH_SHORT).show();
                GPS [0] = LAT2;
                GPS [1] = longitude2;
                GPS [0] = loc.getLatitude();
                GPS [1] = loc.getLongitude();
                Z = loc.getSpeed​​();            }
        }
        公共无效onProviderDisabled(字符串提供商)
        {
            Toast.makeText(getApplicationContext(),全球定位系统已禁用,Toast.LENGTH_SHORT).show();
        }
        公共无效onProviderEnabled(字符串提供商)
        {
            Toast.makeText(getApplicationContext(),GPS功能,Toast.LENGTH_SHORT).show();
        }
        公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员)
        {
            Toast.makeText(getApplicationContext(),状态改变,Toast.LENGTH_SHORT).show();
        }
    }}

清单:

 <?XML版本=1.0编码=UTF-8&GT?;
 <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  包=com.SmartPark
  安卓版code =1
  机器人:=的versionName1.0>
<采用-SDK安卓的minSdkVersion =10/>
    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION>< /使用说明 - 许可>
    <使用许可权的android:NAME =android.permission.ACCESS_LOCATION>< /使用许可权>
<使用许可权的android:NAME =android.permission.ACCESS_GPS>< /使用许可权>
<使用许可权的android:NAME =android.permission.ACCESS_ASSISTED_GPS>< /使用许可权>
<应用机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME>
        <使用库机器人:名字=com.google.android.maps/>
    <活动机器人:名字=。MapviewActivity
              机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>    < /活性GT;
  < /用途> < /清单>

logcat的:

  9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):了java.lang.RuntimeException:无法实例活动ComponentInfo {com.SmartPark / com.SmartPark.MapviewActivity} :抛出java.lang.ClassNotFoundException:com.SmartPark.MapviewActivity装载机dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.SmartPark-2.apk]
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1618)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.ActivityThread.access $ 1500(ActivityThread.java:124)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:968)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.os.Handler.dispatchMessage(Handler.java:99)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.os.Looper.loop(Looper.java:123)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.ActivityThread.main(ActivityThread.java:3806)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在java.lang.reflect.Method.invokeNative(本机方法)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在java.lang.reflect.Method.invoke(Method.java:507)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在dalvik.system.NativeStart.main(本机方法)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):抛出java.lang.ClassNotFoundException:致com.SmartPark.MapviewActivity装载机dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.SmartPark-2.apk]
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在java.lang.ClassLoader.loadClass(ClassLoader.java:551)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在java.lang.ClassLoader.loadClass(ClassLoader.java:511)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.Instrumentation.newActivity(Instrumentation.java:1021)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1610)
9月10日至六日:19:07.239:ERROR / AndroidRuntime(13602):... 11个


解决方案

难道不应该是 MapViewActivity ,而不是 MapviewActivity 在你的清单?

I am struggling with finding the reason why this code locks up. As far as I know, I am declaring the correct permissions in my manifest file as shown below. I have tried running it on an actual device(Droid x w./ 2.3.3) and an AVD to no avail. I've attached the logcat as well which brought me to the classnotfound exception. I have cleaned the project, and verified that the maps.jar is included in the googleapi's package, which I've also used as the target for the application. (Google API's 2.3.3). Not sure where to go from here.

Activity Code:

'package com.SmartPark;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.widget.LinearLayout;
//import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;



public class SmartParkActivity extends MapActivity {
 //** Called when the activity is first created. */
    LinearLayout linearlayout;
    MapView mapView;
    List<Overlay> mapOverlays;
    Drawable drawable;
    HelloItemizedOverlay itemizedOverlay;
    GeoPoint point = new GeoPoint(42392400,-83134700);
    OverlayItem overlayitem = new OverlayItem(point, "", "");
    private LocationManager lm;
    private LocationListener locationListener;
    public double[] gps=new double[2];
    public boolean setgps;
    final Handler mHandler = new Handler();
    //TextView tvl; //latitude display
   // TextView tvlong;//longitude display
    int lat2;
    int longitude2;
    public float z;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.greendot1);
        itemizedOverlay = new HelloItemizedOverlay(drawable);
        OverlayItem overlayitem = new OverlayItem(point, "", "");
        itemizedOverlay.addOverlay(overlayitem);
       mapOverlays.add(itemizedOverlay);
       // tvl =  (TextView) this.findViewById(R.id.gpslview);
      // tvlong =  (TextView) this.findViewById(R.id.gpslongview);
    }

    @Override
    protected boolean isRouteDisplayed() {

            return false;
    }

     @Override
        protected void onStart() {
            super.onStart();


        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        locationListener = new MyLocationListener();

        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0,
                locationListener);

        mHandler.postDelayed(mUpdateTimeTask, 500);



    }
    @Override
    protected void onStop() {
        super.onStop();

       lm.removeUpdates(locationListener);
        mHandler.removeCallbacks(mUpdateTimeTask);
        }

    @Override
    protected void onDestroy() {
        super.onDestroy();

       lm.removeUpdates(locationListener);
        mHandler.removeCallbacks(mUpdateTimeTask);
        }






    //}
 // helper method to schedule the postdelayed mhandler at specified interval
    private boolean foo() { 
        setgps=false;


        mHandler.postDelayed(mUpdateTimeTask, 500);

        return true;
    };


    //Method to acquire set gps variable and display it. update overlay if     possible
    private Runnable mUpdateTimeTask = new Runnable() {
           public void run() {  

               mapOverlays.clear();
               GeoPoint point = setgeopoint(gps[0],gps[1]);
               OverlayItem overlayitem = new OverlayItem(point, "", "");
               mapOverlays.add(itemizedOverlay);
               itemizedOverlay.addOverlay(overlayitem);

              // tvl.setText("Latitude:"+gps[0]);
               //  tvlong.setText("Longitude"+gps[1]);
                 // z=(float)android.location.Location.getSpeed();
                 setgps=foo(); //reschedules the task

    }; 
    };

    //math functions

   //convert gps double to an int and set to GeoPoint
    public GeoPoint setgeopoint (double dl, double dlong) {
        int intl = (int) (dl*1000000);
        int intlong = (int) (dlong*1000000);

        GeoPoint point= new GeoPoint ( intl, intlong);
        return point;
    }




    public class MyLocationListener implements LocationListener
    {
        @Override
        public void onLocationChanged(Location loc)
        {
            if (loc != null) {
                Toast.makeText(
                        getBaseContext(),
                        "Location changed : Lat: " + loc.getLatitude()
                                + " Lng: " + loc.getLongitude(),
                        Toast.LENGTH_SHORT).show();
                gps[0]= lat2;
                gps[1]=longitude2;
                gps[0] = loc.getLatitude();
                gps[1] = loc.getLongitude();
                z=loc.getSpeed();

            }
        }
        public void onProviderDisabled(String provider)
        {
            Toast.makeText( getApplicationContext(),"Gps     Disabled",Toast.LENGTH_SHORT ).show();
        }
        public void onProviderEnabled(String provider)
        {
            Toast.makeText( getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
        }
        public void onStatusChanged(String provider, int status, Bundle extras)
        {
            Toast.makeText( getApplicationContext(),"Status changed",Toast.LENGTH_SHORT).show();
        }
    }





}'

Manifest:

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.SmartPark"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses- permission> 
    <uses-permission android:name="android.permission.ACCESS_LOCATION"></uses-permission> 
<uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission> 
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />
    <activity android:name=".MapviewActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
  </application>

 </manifest>

Logcat:

10-06 09:19:07.239: ERROR/AndroidRuntime(13602): java.lang.RuntimeException: Unable to     instantiate activity ComponentInfo{com.SmartPark/com.SmartPark.MapviewActivity}:     java.lang.ClassNotFoundException: com.SmartPark.MapviewActivity in loader     dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.SmartPark-2.apk]
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1618)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.app.ActivityThread.access$1500(ActivityThread.java:124)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at     android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.os.Looper.loop(Looper.java:123)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.app.ActivityThread.main(ActivityThread.java:3806)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at java.lang.reflect.Method.invokeNative(Native Method)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at java.lang.reflect.Method.invoke(Method.java:507)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at dalvik.system.NativeStart.main(Native Method)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602): Caused by: java.lang.ClassNotFoundException: com.SmartPark.MapviewActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.SmartPark-2.apk]
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1610)
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):     ... 11 more

解决方案

Shouldn't it be MapViewActivity and not MapviewActivity in your manifest?

这篇关于使用MapView类的ClassNotFoundException抛出该异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆