我需要帮助来解决 native Android 应用程序引发的 RuntimeException 问题。 我无法定义导致此异常的原因。这是堆栈跟踪和代码。这里似乎有什么问题?
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1879
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1980
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 122
ActivityThread$H.handleMessage(Message) line: 1146
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4340
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 784
ZygoteInit.main(String[]) line: 551
NativeStart.main(String[]) line: not available [native method]
代码
package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import com.example.hellogooglemaps.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MapView.LayoutParams;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import java.util.List;
import com.google.android.maps.Overlay;
import com.google.android.maps.MapView.LayoutParams;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
public class HellogooglemapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p,p2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
String coordinates[] = {"59.3948", "24.662"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mc.animateTo(p);
mc.setZoom(14);
mapView.invalidate();
}
class MapOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint created in onCreate to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.map_marker);
canvas.drawBitmap(bmp, screenPts.x-15, screenPts.y-32, null);
// add a new marker to coords given below
String coordinates[] = {"59.40", "24.80"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p2 = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6));
Point screenPts2 = new Point();
mapView.getProjection().toPixels(p2, screenPts2);
canvas.drawBitmap(bmp, screenPts2.x-15, screenPts2.y-32, null);
Toast.makeText(getBaseContext(),
p2.getLatitudeE6() / 1E6 + "," +
p2.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
return true;
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
AVD:Google API 14
最佳答案
异常堆栈跟踪 + 消息通常会逐字打印到 logcat。堆栈跟踪的第一行表明,当系统调用 Instrumentation.newActivity(ClassLoader, String, Intent) 时,无法实例化 Activity 对象。在 logcat 中,您应该能够找到类似“无法实例化 Activity
关于java - Android应用程序ActivityThread中的RuntimeException未能找到一些来源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423473/