我正在尝试将一个mapbox放在一个片段中并且它不会膨胀。这是我的logcat:
android.view.InflateException: Binary XML file line #9: Error inflating class com.mapbox.mapboxsdk.views.MapView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at inscope.inscope.Map.onCreateView(Map.java:33)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:251)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mapbox.mapboxsdk.views.MapView" on path: DexPathList[[zip file "/data/app/inscope.inscope-2/base.apk"],nativeLibraryDirectories=[/data/app/inscope.inscope-2/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at inscope.inscope.Map.onCreateView(Map.java:33)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:251)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: com.mapbox.mapboxsdk.views.MapView
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 29 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
03-31 02:37:53.714 1220-1569/system_process W/ActivityManager﹕ Force finishing activity 1 inscope.inscope/.Main
03-31 02:37:53.774 1220-17998/system_process I/OpenGLRenderer﹕ Initialized EGL, version 1.4
03-31 02:37:53.785 1220-17998/system_process W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-31 02:37:53.785 1220-17998/system_process W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0x9e00f7c0, error=EGL_SUCCESS
03-31 02:37:54.230 1220-1238/system_process W/ActivityManager﹕ Activity pause timeout for ActivityRecord{2177629c u0 inscope.inscope/.Main t149 f}
03-31 02:37:55.921 1220-1280/system_process W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
03-31 02:37:55.956 19375-19375/inscope.inscope I/Process﹕ Sending signal. PID: 19375 SIG: 9
03-31 02:37:55.978 1220-17998/system_process D/OpenGLRenderer﹕ endAllStagingAnimators on 0xa21ea080 (RippleDrawable) with handle 0xa21faa00
03-31 02:37:56.005 1220-1389/system_process I/WindowState﹕ WIN DEATH: Window{21136934 u0 inscope.inscope/inscope.inscope.Main}
03-31 02:37:56.009 1220-1628/system_process I/WindowState﹕ WIN DEATH: Window{24af30ca u0 inscope.inscope/inscope.inscope.MainActivity}
03-31 02:37:56.051 1220-1282/system_process I/ActivityManager﹕ Process inscope.inscope (pid 19375) has died
03-31 02:37:56.265 1220-1243/system_process V/WindowManager﹕ Adding window Window{38d8443d u0 Starting inscope.inscope} at 2 of 9 (before Window{21136934 u0 inscope.inscope/inscope.inscope.Main EXITING})
03-31 02:37:56.288 1220-1282/system_process I/ActivityManager﹕ Start proc 19607:inscope.inscope/u0a60 for activity inscope.inscope/.MainActivity
03-31 02:37:56.362 19607-19607/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
03-31 02:37:56.398 19607-19614/? E/art﹕ Failed sending reply to debugger: Broken pipe
03-31 02:37:56.404 934-934/? I/art﹕ Explicit concurrent mark sweep GC freed 710(30KB) AllocSpace objects, 0(0B) LOS objects, 91% free, 92KB/1116KB, paused 2.537ms total 97.855ms
03-31 02:37:56.398 19607-19614/? I/art﹕ Debugger is no longer active
03-31 02:37:56.420 19607-19614/? W/art﹕ Suspending all threads took: 6.845ms
03-31 02:37:56.450 934-934/? I/art﹕ Explicit concurrent mark sweep GC freed 6(208B) AllocSpace objects, 0(0B) LOS objects, 91% free, 92KB/1116KB, paused 1.423ms total 44.264ms
03-31 02:37:56.476 19607-19607/? D/test﹕ before login
03-31 02:37:56.492 934-934/? I/art﹕ Explicit concurrent mark sweep GC freed 5(160B) AllocSpace objects, 0(0B) LOS objects, 91% free, 92KB/1116KB, paused 24.549ms total 39.827ms
03-31 02:37:56.699 19607-19607/? D/test﹕ set view to login_screen
03-31 02:37:56.821 19607-19631/? D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-31 02:37:56.825 19607-19607/? D/﹕ HostConnection::get() New Host Connection established 0xb42b3c30, tid 19607
03-31 02:37:56.833 19607-19607/? D/Atlas﹕ Validating map...
03-31 02:37:56.835 1220-1569/system_process V/WindowManager﹕ Adding window Window{18bdf5 u0 inscope.inscope/inscope.inscope.MainActivity} at 2 of 9 (before Window{38d8443d u0 Starting inscope.inscope})
03-31 02:37:56.852 19607-19619/? I/art﹕ Background partial concurrent mark sweep GC freed 347(41KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 32MB/36MB, paused 6.947ms total 71.880ms
03-31 02:37:56.884 19607-19631/? D/﹕ HostConnection::get() New Host Connection established 0xb43fa370, tid 19631
03-31 02:37:56.895 19607-19631/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4
03-31 02:37:56.914 19607-19631/? D/OpenGLRenderer﹕ Enabling debug mode 0
03-31 02:37:56.923 19607-19631/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-31 02:37:56.924 19607-19631/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb43b2ae0, error=EGL_SUCCESS
03-31 02:37:57.223 1220-1243/system_process I/ActivityManager﹕ Displayed inscope.inscope/.MainActivity: +971ms
03-31 02:37:57.226 1220-1372/system_process W/InputMethodManagerService﹕ Got RemoteException sending setActive(false) notification to pid 19375 uid 10060
03-31 02:38:22.030 1220-2153/system_process I/art﹕ Explicit concurrent mark sweep GC freed 35331(1734KB) AllocSpace objects, 11(173KB) LOS objects, 33% free, 7MB/11MB, paused 1.285ms total 26.801ms
03-31 02:38:22.086 1685-19806/com.google.process.gapps I/GoogleURLConnFactory﹕ binding HttpService
03-31 02:38:22.086 1685-19806/com.google.process.gapps I/GoogleHttpClient﹕ Falling back to old SSLCertificateSocketFactory
03-31 02:38:22.147 1685-19806/com.google.process.gapps W/Uploader﹕ No account for auth token provided
03-31 02:38:22.287 1685-19806/com.google.process.gapps W/Uploader﹕ No account for auth token provided
03-31 02:38:22.404 1685-19806/com.google.process.gapps W/Uploader﹕ no longer exists, so no auth token.
03-31 02:38:22.549 1685-19806/com.google.process.gapps W/Uploader﹕ No account for auth token provided
03-31 02:38:22.643 1685-19806/com.google.process.gapps W/Uploader﹕ No account for auth token provided
03-31 02:38:22.743 1685-19806/com.google.process.gapps W/Uploader﹕ No account for auth token provided
03-31 02:38:22.885 1685-1696/com.google.process.gapps E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'end' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at java.util.zip.Inflater.<init>(Inflater.java:82)
at com.android.okio.GzipSource.<init>(GzipSource.java:57)
at com.android.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:490)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:680)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:806)
at com.google.android.gms.http.GoogleHttpClient.b(SourceFile:770)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:673)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:664)
at com.google.android.gms.playlog.uploader.b.a(SourceFile:332)
at com.google.android.gms.playlog.uploader.b.a(SourceFile:227)
at com.google.android.gms.playlog.uploader.b.a(SourceFile:199)
at com.google.android.gms.playlog.uploader.UploaderService.a(SourceFile:39)
at com.google.android.gms.gcm.af.run(SourceFile:130)
03-31 02:38:27.903 1685-1696/com.google.process.gapps E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'end' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at java.util.zip.Inflater.<init>(Inflater.java:82)
at com.android.okio.GzipSource.<init>(GzipSource.java:57)
at com.android.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:490)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:680)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:806)
at com.google.android.gms.http.GoogleHttpClient.b(SourceFile:770)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:673)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:664)
at com.google.android.gms.playlog.uploader.b.a(SourceFile:332)
at com.google.android.gms.playlog.uploader.b.a(SourceFile:227)
at com.google.android.gms.playlog.uploader.b.a(SourceFile:199)
at com.google.android.gms.playlog.uploader.UploaderService.a(SourceFile:39)
at com.google.android.gms.gcm.af.run(SourceFile:130)
03-31 02:39:22.017 1685-1685/com.google.process.gapps W/GCM﹕ Heartbeat timeout, GCM connection reset
03-31 02:39:22.041 1220-1372/system_process D/ConnectivityService﹕ reportBadNetwork(NetworkAgentInfo [MOBILE (UMTS) - 100]) by 10007
03-31 02:39:22.049 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ ValidatedState{ when=-6ms what=532488 arg1=10007 target=com.android.internal.util.StateMachine$SmHandler }
03-31 02:39:22.049 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ DefaultState{ when=-8ms what=532488 arg1=10007 target=com.android.internal.util.StateMachine$SmHandler }
03-31 02:39:22.049 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Forcing reevaluation
03-31 02:39:22.050 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ EvaluatingState{ when=-1ms what=532486 arg1=3 target=com.android.internal.util.StateMachine$SmHandler }
03-31 02:39:22.055 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Checking http://connectivitycheck.android.com/generate_204 on epc.tmobile.com
03-31 02:39:22.087 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ isCaptivePortal: ret=204 headers={null=[HTTP/1.1 204 No Content], Content-Length=[0], Date=[Thu, 31 Mar 2016 06:40:08 GMT], X-Android-Received-Millis=[1459406362087], X-Android-Response-Source=[NETWORK 204], X-Android-Sent-Millis=[1459406362075]}
03-31 02:39:22.087 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Don't send network conditions - lacking user consent.
03-31 02:39:22.087 1220-1679/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Validated
03-31 02:39:22.089 1220-1276/system_process D/ConnectivityService﹕ setProvNotificationVisibleIntent: E visible=false networkType=0 extraInfo=null
03-31 02:39:22.090 1220-1276/system_process D/ConnectivityService﹕ Validated NetworkAgentInfo [MOBILE (UMTS) - 100]
03-31 02:39:31.679 1685-20285/com.google.process.gapps D/GCM﹕ Connected
03-31 02:39:31.719 1685-20285/com.google.process.gapps D/GCM﹕ Message class com.google.e.a.a.q
03-31 02:41:04.560 19607-19614/inscope.inscope W/art﹕ Suspending all threads took: 15.170ms
03-31 02:44:00.059 1220-1238/system_process I/ProcessStatsService﹕ Prepared write state in 1ms
这是我的片段类:
public class Map extends android.support.v4.app.Fragment {
private MapView mapView;
public Map() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_map, container, false);
MapView mapView = (MapView) layout.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
// Set map style
mapboxMap.setStyleUrl(Style.MAPBOX_STREETS);
// Set the camera's starting position
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(41.885, -87.679)) // set the camera's center position
.zoom(12) // set the camera's zoom level
.tilt(20) // set the camera's tilt
.build();
// Move the camera to that position
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});
return layout;
}
这是xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="inscope.inscope.Map">
<!-- TODO: Update blank fragment layout -->
<com.mapbox.mapboxsdk.views.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapbox:access_token="my Token" />
我已经按照他们网站上的地图框说明进行了gradle和权限,所以我确信这些没有任何问题。它说“View layout = inflater ...”这一行出了问题,除了我无法弄清楚可能出现什么问题。
答案 0 :(得分:2)
我想在@Tirth Allspark Rami的回答中加一点。
onLogin(){
Alert.alert(
'Acceso',
'Te has logueado en el sistema',
[
{text: 'Aceptar',
onPress:() => this.props.navigation.navigate('Dashboard')},
{text: 'Cancelar',
onPress:(this.cancelar.bind(this))}
]
)
}
应该在
之后Mapbox.getInstance(this,access_token)
在指定任何布局进行查看之前。
答案 1 :(得分:0)
使用昨天发布的4.0.0更新,您需要将xml从com.mapbox.mapboxsdk.views.MapView
调整为<com.mapbox.mapboxsdk.maps.MapView
。
此外,我还想从测试应用推荐这个example,因为您在片段中使用了mapview。