package com.satyam.curlocation;
import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public abstract class CurLocationActivity extends Activity {
LocationManager mlocationManager;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.tv1);
mlocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String locationprovider = mlocationManager.getBestProvider(criteria,true);
Location mlocation = mlocationManager.getLastKnownLocation(locationprovider);
if(mlocation != null){
tv.setText("Last location lat: " + mlocation.getLatitude()+" long:" +mlocation.getLongitude());
}
else{
tv.setText("No last location available");
}
}
}
而只是運行我發現錯誤,如的Android當前的位置誤差線程錯誤
03-06 17:07:07.122: W/dalvikvm(11854): threadid=1: thread exiting with uncaught exception (group=0x40015560)
我沒有找到答案的代碼。我感到很震驚。
編輯:
logcat的: 它顯示錯誤信息是這樣的:
03-07 14:59:22.406: E/AndroidRuntime(20362): FATAL EXCEPTION: main
03-07 14:59:22.406: E/AndroidRuntime(20362): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.satyam.curlocation/com.satyam.curlocation.CurLocationActivity}: java.lang.InstantiationException: com.satyam.curlocation.CurLocationActivity
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.os.Looper.loop(Looper.java:130)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 14:59:22.406: E/AndroidRuntime(20362): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 14:59:22.406: E/AndroidRuntime(20362): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 14:59:22.406: E/AndroidRuntime(20362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-07 14:59:22.406: E/AndroidRuntime(20362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-07 14:59:22.406: E/AndroidRuntime(20362): at dalvik.system.NativeStart.main(Native Method)
03-07 14:59:22.406: E/AndroidRuntime(20362): Caused by: java.lang.InstantiationException: com.satyam.curlocation.CurLocationActivity
03-07 14:59:22.406: E/AndroidRuntime(20362): at java.lang.Class.newInstanceImpl(Native Method)
03-07 14:59:22.406: E/AndroidRuntime(20362): at java.lang.Class.newInstance(Class.java:1409)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-07 14:59:22.406: E/AndroidRuntime(20362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
03-07 14:59:22.406: E/AndroidRuntime(20362): ... 11 more
墜毀顯示力全封閉錯誤。
你有更多的錯誤信息?應用程序崩潰還是警告您在logcat中看到的唯一一件事情? – WarrenFaith 2012-03-06 11:54:51
我編輯了代碼!!! – NovusMobile 2012-03-06 13:50:35
這是完整的錯誤stacktrace?而已?我只在第二個stacktrace的右下方出現這個錯誤。請再次檢查(您的活動代碼看起來很好) – WarrenFaith 2012-03-06 14:14:56