Ошибка текущего местоположения Android - PullRequest
0 голосов
/ 06 марта 2012
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");
    }
}

}    

при запуске кода я обнаружил ошибку типа

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

Произошел сбой отображения силы. Ошибка полного закрытия.

1 Ответ

1 голос
/ 07 марта 2012
public abstract class CurLocationActivity

Проблема в abstract, Удалите it And Rerun ...

Если вам нужно попробовать лайк

public class MainActivity extends YourAbstractClass 

И использовать YourAbstractClass extends Activity

...