Could not find cool Android exception

I work with two separate classes, one of which has several buttons, and the other opens Google maps, and I write on it. If anyone saw a problem with my intention to open Map.class, let me know. I will write 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) 
+4
source share
7 answers

This may be one of the following reasons in the order of probability (and therefore of the reverse order of rarity)

  • Problems with AndroidManifest.xml. <activity> , declaration <uses-library android:name="com.google.android.maps" /> in the <application> section, etc.
  • Configuration issues: manually adding maps.jar files, and setting the project type to use the Google APIs. For some reason this causes problems.
  • Finally, you cause activity, some class which causes this problem can inherit. I had the same problem calling MapActivity from a class that used the droidFu API. The calling activity used the droidFu BetterActivity inheritance. I only got a map to work after I changed MapActivity to BetterMapActivity from the droidFu API.
+12
source

There was the same problem and solved by adding this to AndroidManifest.xml between application tags

 <application ... ... > **<uses-library android:name="com.google.android.maps" />** <activity .... /> </application> 
+4
source

Did you get the Google API map key and specify it in R.layout.map? Also, do not forget to allow access in the manifest to access the Internet.

+2
source

Do you have a <activity/> element for the activity of your map in your AndroidManifest.xml?

0
source

Take a look at some of the answers in the Google Maps API for Android giving NoClassDefFoundError and NoClassDefFoundError in mapActivity to cover most of the possibilities.

0
source

extends cbHome class to MapActivity

0
source

If you are in some kind of action, and want to display the map, and it gives the above error, then this is due to the absence of this line of code in android.manifest, so put this code and go from the error.

  <application ....... <uses-library android:name="com.google.android.maps" /> //this is your required code <activity ..... </activity> </application> 
0
source

Source: https://habr.com/ru/post/1346084/


All Articles