android - java.lang.RuntimeException - maps activity -
when try luch application, error message appear
this error message:
04-14 19:19:06.846 18713-18713/ms_br.appriuso d/androidruntime: shutting down vm --------- beginning of crash 04-14 19:19:06.847 18713-18713/ms_br.appriuso e/androidruntime: fatal exception: main process: ms_br.appriuso, pid: 18713 java.lang.runtimeexception: unable instantiate activity componentinfo{ms_br.appriuso/ms_br.appriuso.mapsactivity}: java.lang.instantiationexception: java.lang.class<ms_br.appriuso.mapsactivity> cannot instantiated @ android.app.activitythread.performlaunchactivity(activitythread.java:2568) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2727) @ android.app.activitythread.-wrap12(activitythread.java) @ android.app.activitythread$h.handlemessage(activitythread.java:1478) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:154) @ android.app.activitythread.main(activitythread.java:6121) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:889) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:779) caused by: java.lang.instantiationexception: java.lang.class<ms_br.appriuso.mapsactivity> cannot instantiated @ java.lang.class.newinstance(native method) @ android.app.instrumentation.newactivity(instrumentation.java:1078) @ android.app.activitythread.performlaunchactivity(activitythread.java:2558) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2727) @ android.app.activitythread.-wrap12(activitythread.java) @ android.app.activitythread$h.handlemessage(activitythread.java:1478) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:154) @ android.app.activitythread.main(activitythread.java:6121) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:889) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:779)
manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ms_br.appriuso"> <!--permission list--> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <application android:name=".app.appcontroller" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme"> <!-- android:debuggable="true">--> <activity android:name=".loginactivity" android:label="@string/app_name" android:launchmode="singletop" android:windowsoftinputmode="adjustpan"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".registeractivity" android:label="@string/app_name" android:launchmode="singletop" android:windowsoftinputmode="adjustpan" /> <activity android:name=".mainactivity" android:label="@string/app_name" android:launchmode="singletop" /> <!-- api key google maps-based apis defined string resource. (see file "res/values/google_maps_api.xml"). note api key linked encryption key used sign apk. need different api key each encryption key, including release key used sign apk publishing. can define keys debug , release targets in src/debug/ , src/release/. --> <meta-data android:name="com.google.android.geo.api_key" android:value="@string/google_maps_key" /> <activity android:name=".mapsactivity" android:label="@string/title_activity_maps" /> </application> </manifest>
code
package ms_br.appriuso; import android.content.intentsender; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.util.log; import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.api.googleapiclient; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; import com.google.android.gms.location.locationrequest; import com.google.android.gms.location.locationservices; //import com.google.android.gms.common.internal.safeparcel.abstractsafeparcelable; import android.location.location; import com.google.android.gms.location.locationlistener; abstract class mapsactivity extends fragmentactivity implements googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener, locationlistener { public static final string tag = mapsactivity.class.getsimplename(); /* * define request code send google play services * code returned in activity.onactivityresult */ private final static int connection_failure_resolution_request = 9000; private googlemap mmap; // might null if google play services apk not available. private googleapiclient mgoogleapiclient; private locationrequest mlocationrequest; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); setupmapifneeded(); mgoogleapiclient = new googleapiclient.builder(this) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .addapi(locationservices.api) .build(); // create locationrequest object mlocationrequest = locationrequest.create() .setpriority(locationrequest.priority_high_accuracy) .setinterval(10 * 1000) // 10 seconds, in milliseconds .setfastestinterval(1 * 1000); // 1 second, in milliseconds } @override protected void onresume() { super.onresume(); setupmapifneeded(); mgoogleapiclient.connect(); } @override protected void onpause() { super.onpause(); if (mgoogleapiclient.isconnected()) { locationservices.fusedlocationapi.removelocationupdates(mgoogleapiclient, this); mgoogleapiclient.disconnect(); } } /** * sets map if possible (i.e., google play services apk correctly * installed) , map has not been instantiated.. ensure ever * call {@link #setupmap()} once when {@link #mmap} not null. * <p/> * if isn't installed {@link supportmapfragment} (and * {@link com.google.android.gms.maps.mapview mapview}) show prompt user * install/update google play services apk on device. * <p/> * user can return fragmentactivity after following prompt , correctly * installing/updating/enabling google play services. since fragmentactivity may not * have been destroyed during process (it * stopped or paused), {@link #oncreate(bundle)} may not called again should call * method in {@link #onresume()} guarantee called. */ private void setupmapifneeded() { // null check confirm have not instantiated map. if (mmap == null) { // try obtain map supportmapfragment. /*mmap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)) .getmap();*/ // check if successful in obtaining map. if (mmap != null) { setupmap(); } } } /** * can add markers or lines, add listeners or move camera. in case, * add marker near africa. * <p/> * should called once , when sure {@link #mmap} not null. */ private void setupmap() { mmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("marker")); } private void handlenewlocation(location location) { log.d(tag, location.tostring()); double currentlatitude = location.getlatitude(); double currentlongitude = location.getlongitude(); latlng latlng = new latlng(currentlatitude, currentlongitude); //mmap.addmarker(new markeroptions().position(new latlng(currentlatitude, currentlongitude)).title("current location")); markeroptions options = new markeroptions() .position(latlng) .title("i here!"); mmap.addmarker(options); mmap.movecamera(cameraupdatefactory.newlatlng(latlng)); } @override public void onconnected(bundle bundle) { location location = locationservices.fusedlocationapi.getlastlocation(mgoogleapiclient); if (location == null) { locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, mlocationrequest, this); } else { handlenewlocation(location); } } @override public void onconnectionsuspended(int i) { } @override public void onconnectionfailed(connectionresult connectionresult) { /* * google play services can resolve errors detects. * if error has resolution, try sending intent * start google play services activity can resolve * error. */ if (connectionresult.hasresolution()) { try { // start activity tries resolve error connectionresult.startresolutionforresult(this, connection_failure_resolution_request); /* * thrown if google play services canceled original * pendingintent */ } catch (intentsender.sendintentexception e) { // log error e.printstacktrace(); } } else { /* * if no resolution available, display dialog * user error. */ log.i(tag, "location services connection failed code " + connectionresult.geterrorcode()); } } @override public void onlocationchanged(location location) { handlenewlocation(location); } }
code xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="ms_br.appriuso.mapsactivity" tools:layout="@layout/activity_maps" />
can me?
some details: - usb debug google pixel android n 7.1.2 - android studio 2.3.1
i tried everything. come out crazy!:/
thanks
because instantiationexception, means android not able create new instance of activity.
you should change mapactivity no longer abstract.
abstract class mapsactivity
public class mapsactivity
Comments
Post a Comment