Android current location error Thread error
-
08-12-2019 - |
Question
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");
}
}
}
while just running the code I found the error like
03-06 17:07:07.122: W/dalvikvm(11854): threadid=1: thread exiting with uncaught exception (group=0x40015560)
I didn't find the answer. I am struck at this point.
Edited:
logcat: It display error message like this:
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
It crashed display force Full closed error.
Solution
public abstract class CurLocationActivity
The Problem is abstract
,Remove it And Rerun...
If you need try Like
public class MainActivity extends YourAbstractClass
And Use YourAbstractClass extends Activity
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow