找不到类异常的Andr​​oid找不到、异常、oid、Andr

2023-09-06 17:30:09 作者:与君语

我有两个独立的类工作,其中一个有一些按钮和其他打开谷歌地图,我就可以做一个叠加。如果任何人都可以看到我的意图来打开问题Map.class让我知道。我会扔在我的错误消息和code。

 包com.state.park;




进口的java.util.ArrayList;
进口的java.util.List;
进口android.graphics.Canvas;
进口android.graphics.Color;
进口android.graphics.Paint;
进口android.graphics.Path;
进口android.graphics.Point;
进口android.graphics.Paint.Style;
进口android.graphics.drawable.Drawable;
进口android.widget.LinearLayout;
进口com.google.android.maps.GeoPoint;
进口com.google.android.maps.ItemizedOverlay;
进口com.google.android.maps.OverlayItem;
进口com.google.android.maps.MapActivity;
进口com.google.android.maps.MapView;
进口com.google.android.maps.Projection;


进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.Button;
公共类地图扩展MapActivity {

    私人图形页面图形页面;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        的setContentView(R.layout.map);

        图形页面=(图形页面)findViewById(R.id.mapview);

        mapView.setBuiltInZoomControls(真正的);

        mapView.setClickable(真正的);

        绘制对象标记= getResources()getDrawable(R.drawable.icon)。
        marker.setBounds(0,0,marker.getIntrinsicWidth(),marker.getIntrinsicHeight());

        InterestingLocations funPlaces =新InterestingLocations(标记);
        。调用MapView.getOverlays()加(funPlaces);
        的GeoPoint PT = funPlaces.getCenter();
        mapView.getController()setCenter(PT)。
        mapView.getController()setZoom(15)。
    }

    @覆盖
    保护的布尔isRouteDisplayed(){
        // TODO自动生成方法存根
        返回false;
    }

    类InterestingLocations扩展ItemizedOverlay {

        私人列表< OverlayItem>位置=新的ArrayList< OverlayItem>();

        私人绘制对象标记;
        私人的GeoPoint P1,P2,P3;
        民营涂料粉刷;
        公共InterestingLocations(可绘制defaultMarker){
            超(defaultMarker);

            标记= defaultMarker;

             P1 =新的GeoPoint((INT)(34.044125 * 1000000),(INT)( -  77.912636 * 1000000));
             P2 =新的GeoPoint((INT)(34.046544 * 1000000),(INT)(-77.918043 * 1000000));
             P3 =新的GeoPoint((INT)(34.041992 * 1000000),(INT)( -  77.921476 * 1000000));



            locations.add(新OverlayItem(P1,special1,special1));
            locations.add(新OverlayItem(P2,SPECIAL2,special12));
            locations.add(新OverlayItem(P3,special3,special3));
            // TODO自动生成构造函数存根
            填充();
        }

        公共无效画(油画画布,图形页面图形页面,布尔影子){
             super.draw(帆布,图形页面,阴影);

             boundCenterBottom(标记);

             从=新的点对点();
             指向=新的点();

             油漆=新的油漆();

                paint.setColor(Color.BLACK);
                paint.setStrokeWidth(2);
                paint.setStyle(Style.FILL);

             路径path =新路径();
              投影PROJ = MapView.getProjection()在;
              proj.toPixels(P1,从);
              proj.toPixels(P2,到);
              path.moveTo(from.x,from.y);
              path.lineTo(to.x,to.y);
              canvas.drawLine(from.x,from.y,to.x,to.y,油漆);



        }

        @覆盖
        保护OverlayItem createItem中(int i)以{
            // TODO自动生成方法存根
            返回locations.get(ⅰ);
        }

        @覆盖
        公众诠释大小(){
            // TODO自动生成方法存根
            返回locations.size();
        }


    }
}
 

 包com.state.park;

进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;

公共类CBHome延伸活动{
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        按钮POI =(按钮)findViewById(R.id.poi);

        POI.setOnClickListener(新View.OnClickListener(){

            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根

                意图I =新的意图(CBHome.this,Map.class);

                CBHome.this.startActivity(ⅰ);

            }



        });

    }



}
 

  03-31 17:15:51.882:ERROR / dalvikvm(1033):找不到类的com.state.park.Map,从法com.state.park引用.CBHome $ 1.onClick
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):致命异常:主要
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):java.lang.NoClassDefFoundError的:com.state.park.Map
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在com.state.park.CBHome $ 1.onClick(CBHome.java:25)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在android.view.View.performClick(View.java:2408)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在android.view.View $ PerformClick.run(View.java:8816)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在android.os.Handler.handleCallback(Handler.java:587)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在android.os.Handler.dispatchMessage(Handler.java:92)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在android.os.Looper.loop(Looper.java:123)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在android.app.ActivityThread.main(ActivityThread.java:4627)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在java.lang.reflect.Method.invokeNative(本机方法)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在java.lang.reflect.Method.invoke(Method.java:521)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-31 17:15:55.133:ERROR / AndroidRuntime(1033):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

这可能是以下原因之一,以概率(和稀有性,因此逆顺序)

在AndroidManifest.xml中的问题。 <活性GT; 标签,<使用库机器人:名称=com.google.android.maps/> 声明中的<应用> 部分,等等 安装问题:加入maps.jar文件手动以及设置使用谷歌API的项目类型。这导致问题的某些原因。 最后,你叫活动可能会继承一些类,导致此问题。我有同样的问题调用从使用的 droidFu API类中的MapActivity。调用活动中使用droidFu的BetterActivity继承。我只拿到了地图的工作后,我从droidFu API改变了MapActivity到BetterMapActivity。

I am working with two seperate classes one of which has some buttons and the other opens google maps and I am doing an overlay on it. If anyone could see the problem with my intent to open the Map.class let me know. I will throw in my error messages and code.

package com.state.park;




import java.util.ArrayList;
import java.util.List;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;
import android.widget.LinearLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Projection;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Map extends MapActivity {

    private MapView mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.map);

        mapView = (MapView) findViewById(R.id.mapview);

        mapView.setBuiltInZoomControls(true);

        mapView.setClickable(true);

        Drawable marker = getResources().getDrawable(R.drawable.icon);
        marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());

        InterestingLocations funPlaces = new InterestingLocations(marker);
        mapView.getOverlays().add(funPlaces);
        GeoPoint pt = funPlaces.getCenter();
        mapView.getController().setCenter(pt);
        mapView.getController().setZoom(15);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    class InterestingLocations extends ItemizedOverlay{

        private List<OverlayItem> locations = new ArrayList<OverlayItem>();

        private Drawable marker;
        private GeoPoint p1, p2 ,p3;
        private Paint paint;
        public InterestingLocations(Drawable defaultMarker) {
            super(defaultMarker);

            marker = defaultMarker;

             p1 = new GeoPoint((int)(34.044125 * 1000000) , (int)(-77.912636 * 1000000));
             p2 = new GeoPoint((int)(34.046544 * 1000000) , (int) (-77.918043 * 1000000));
             p3 = new GeoPoint((int) (34.041992 * 1000000) , (int)(-77.921476 * 1000000));



            locations.add(new OverlayItem(p1 , "special1" , "special1"));
            locations.add(new OverlayItem(p2 , "special2" , "special12"));
            locations.add(new OverlayItem(p3 , "special3" , "special3"));
            // TODO Auto-generated constructor stub
            populate();
        }

        public void draw(Canvas canvas, MapView mapView , boolean shadow){
             super.draw(canvas, mapView, shadow);

             boundCenterBottom(marker);

             Point from = new Point();
             Point to = new Point();

             paint = new Paint();

                paint.setColor(Color.BLACK);
                paint.setStrokeWidth(2);
                paint.setStyle(Style.FILL);

             Path path = new Path();        
              Projection proj = mapView.getProjection();       
              proj.toPixels(p1,from );       
              proj.toPixels(p2, to);     
              path.moveTo(from.x, from.y);     
              path.lineTo(to.x,to.y);      
              canvas.drawLine(from.x, from.y, to.x, to.y, paint); 



        }

        @Override
        protected OverlayItem createItem(int i) {
            // TODO Auto-generated method stub
            return locations.get(i);
        }

        @Override
        public int size() {
            // TODO Auto-generated method stub
            return locations.size();
        }   


    }
}

package com.state.park;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

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

        Button POI = (Button)findViewById(R.id.poi);

        POI.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i = new Intent(CBHome.this , Map.class);

                CBHome.this.startActivity(i);

            }



        });

    }



}

03-31 17:15:51.882: ERROR/dalvikvm(1033): Could not find class 'com.state.park.Map', referenced from method com.state.park.CBHome$1.onClick
03-31 17:15:55.133: ERROR/AndroidRuntime(1033): FATAL EXCEPTION: main
03-31 17:15:55.133: ERROR/AndroidRuntime(1033): java.lang.NoClassDefFoundError: com.state.park.Map
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at com.state.park.CBHome$1.onClick(CBHome.java:25)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at android.view.View.performClick(View.java:2408)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at android.view.View$PerformClick.run(View.java:8816)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at android.os.Handler.handleCallback(Handler.java:587)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at android.os.Looper.loop(Looper.java:123)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at java.lang.reflect.Method.invokeNative(Native Method)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at java.lang.reflect.Method.invoke(Method.java:521)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-31 17:15:55.133: ERROR/AndroidRuntime(1033):     at dalvik.system.NativeStart.main(Native Method)

解决方案

It may be one of the following reasons in order of probability (and therefore inverse order of rarity)

AndroidManifest.xml problems. <activity> tags, <uses-library android:name="com.google.android.maps" /> declaration in the <application> section, etc. Setup problems: adding the maps.jar files manually as well as setting the project type to use Google APIs. This cause problems for some reason. Finally, you calling activity may be inheriting some class that causes this problem. I had the same problem calling a MapActivity from a class that used the droidFu API. The calling activity used droidFu's BetterActivity inheritance. I only got the map to work after I changed the MapActivity to BetterMapActivity from the droidFu API.