我在Google Maps for Android上制作了一个关于按地址搜索的项目。 当我运行它时,它总是显示强制关闭通知。
这是logcat上的错误:原因:java.lang.ClassNotFoundException:loader dalvic.system.PathClassLoader中的com.ind.findaddress [data / app / com.ind-2.apk]
这是findaddress的代码
public class findadrress extends com.google.android.maps.MapActivity {
private Button btnSearch;
private EditText adress;
private Geocoder gc;
public double lat;
public double lon;
private MapView myMap;
MapController controller;
GeoPoint p;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form_lokasi);
myMap = (MapView) findViewById(R.id.simpleGM_map);
btnSearch = (Button) findViewById(R.id.cariLokasiManual);
adress = (EditText) findViewById(R.id.simpleGM_adress);
gc = new Geocoder(this, Locale.getDefault());
btnSearch.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
List<Address> addresses;
try {
addresses = gc.getFromLocationName(adress.getText().toString(),5);
if(addresses.size() > 0)
{
p = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
controller.animateTo(p);
controller.setZoom(12);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = myMap.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
myMap.invalidate();
adress.setText("");
}
else
{
AlertDialog.Builder adb = new AlertDialog.Builder(findaddress.this);
adb.setTitle("Google Map");
adb.setMessage("Please Provide the Proper Place");
adb.setPositiveButton("Close",null);
adb.show();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
class MapOverlay extends com.google.android.maps.Overlay
{
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-32, null);
return true;
}}
} );
};
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}