这是我的 MainActivity.java 代码
package com.example.com.draft1;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.view.KeyEvent;
import com.google.android.maps.MapController;
public class MainActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
String coordinates[]={"1.352566007","103.78921587"};
double lat=Double.parseDouble(coordinates[0]);
double lng=Double.parseDouble(coordinates[1]);
@Override
public void onCreate(Bundle savedInstanceState) {
p=new GeoPoint((int)(lat*1E6),(int)(lng*1E6));
mapView=(MapView)findViewById(R.id.mapView);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mc.setCenter(p);
//mc.setZoom(13);
//mapView.invalidate();
//myMapController.setCenter(new GeoPoint((int)(lat*1E6),(int)(lng*1E6)));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed()
{
//adssad
return false;
}
}
现在,上面的代码导致强制关闭。
以下是上述的 LogCat 详细信息:09-23 16:37:38.494: D/dalvikvm(18710): GC_CONCURRENT freed 244K, 41% free 3354K/5639K, external 0K/0K, paused 3ms+4ms 09-23 16: 37:38.764: D/dalvikvm(18710): GC_CONCURRENT 释放 530K, 44% 空闲 3378K/5959K, 外部 0K/0K, 暂停 2ms+7ms 09-23 16:37:38.894: D/dalvikvm(18710): GC_CONCURRENT 释放 376K , 42% free 3513K/5959K, external 0K/0K, paused 3ms+4ms 09-23 16:37:39.014: D/dalvikvm(18710): GC_CONCURRENT freed 510K, 43% free 3523K/6087K, external 0K/0K, paused 3ms+4ms 09-23 16:37:39.134: D/dalvikvm(18710): GC_CONCURRENT freed 334K, 40% free 3700K/6087K, external 0K/0K, paused 3ms+4ms 09-23 16:37:39.194: I/ HtcTextSelection(18710): (sendOnTextChanged) stopTextSelectionMode 09-23 16:37:39.244: D/dalvikvm(18710): GC_EXTERNAL_ALLOC 释放 698K,47% 释放 3319K/6151K,外部 0K/0K,暂停 45 毫秒 09-23 16:37:39.264: D/AndroidRuntime(18710): 关闭 VM 09-23 16:37:39.264: W/dalvikvm(18710): threadid=1: 线程退出未捕获异常 (group=0x400dc5a0 ) 09-23 16:37:39.264: E/AndroidRuntime(18710): 致命异常: main 09-23 16:37:39.264: E/AndroidRuntime(18710): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com .example.com.draft1/com.example.com.draft1.MainActivity}:java.lang.NullPointerException 09-23 16:37:39.264:E/AndroidRuntime(18710):在 android.app.ActivityThread.performLaunchActivity(ActivityThread. java:1872) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893) 09-23 16:37:39.264: E/AndroidRuntime(18710) : 在 android.app.ActivityThread.access$1500(ActivityThread.java:135) 09-23 16:37:39.264:E/AndroidRuntime(18710): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.os.Handler.dispatchMessage(Handler .java:99) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.os.Looper.loop(Looper.java:150) 09-23 16:37:39.264: E/AndroidRuntime(18710 ): 在 android.app.ActivityThread.main(ActivityThread.java:4389) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 java.lang.reflect.Method.invokeNative(Native Method) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 java.lang.reflect.Method.invoke(Method.java:507) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 com.android .internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849) 09-23 16:37:39.264: E/AndroidRuntime(18710): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 607) 09-23 16:37:39.264:E/AndroidRuntime(18710):在 dalvik.system.NativeStart.main(本机方法)09-23 16:37:39.264:E/AndroidRuntime(18710):引起:java.lang.NullPointerException 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 com.example.com.draft1.MainActivity.onCreate(MainActivity.java:40) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android .app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836) 09-23 16:37 :39.264: E/AndroidRuntime(18710): ... 11 更多MainActivity.onCreate(MainActivity.java:40) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836) 09-23 16:37:39.264: E/AndroidRuntime(18710): ... 11 更多MainActivity.onCreate(MainActivity.java:40) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) 09-23 16:37:39.264: E/AndroidRuntime(18710): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836) 09-23 16:37:39.264: E/AndroidRuntime(18710): ... 11 更多
因此,当我评论 .setCenter() 语句时,该应用程序运行良好。但是,在取消注释时,它会强制关闭
任何线索,为什么会这样?
感谢您的所有帮助