gpt4 book ai didi

Android slider 库在包含到我的应用程序时崩溃?

转载 作者:行者123 更新时间:2023-11-29 20:15:43 25 4
gpt4 key购买 nike

我试图包括这个 Slider library进入我的代码。

当我将它添加到我的布局时:

<SlidingLayer
android:id="@+id/slidingLayer1"
android:layout_width="match_parent"
android:layout_height="@dimen/layer_height"
android:elevation="2dip"
android:layout_above="@+id/linearLayout"
android:layout_alignParentStart="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_light">

<WebView
android:id="@+id/authWebView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:drawablePadding="15dip"
android:paddingBottom="80dp"
android:textSize="17sp"
android:textColor="@color/primary_text"/>

<Button
android:id="@+id/buttonClose"
style="@style/ButtonRed"
android:onClick="buttonClicked"
android:layout_marginBottom="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/close_button_container"/>
</RelativeLayout>
</SlidingLayer>

包括

private SlidingLayer mSlidingLayer;

然后,在 onCreate() 中:

setContentView(R.layout.activity_main);
initSlider();

并进一步在 initSlider() 方法中:

private void initSlider() {
mSlidingLayer = (SlidingLayer) findViewById(R.id.slidingLayer1);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
setupSlidingLayerPosition(prefs.getString("layer_location", "bottom"));
setupSlidingLayerTransform(prefs.getString("layer_transform", "none"));
setupShadow(prefs.getBoolean("layer_has_shadow", false));
setupLayerOffset(prefs.getBoolean("layer_has_offset", false));
setupPreviewMode(prefs.getBoolean("preview_mode_enabled", false));
}

而 initSlider() 中的 setup* 方法取自 here .

但是我的应用程序在 onCreate() 中的 setcontentview 处崩溃并出现以下错误消息:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mysliderapp, PID: 22831 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mysliderapp/com.mysliderapp.MainActivity}: android.view.InflateException: Binary XML file line #46: Error inflating class SlidingLayer at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255) at android.app.ActivityThread.access$800(ActivityThread.java:142) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5118) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #46: Error inflating class SlidingLayer at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at android.view.LayoutInflater.inflate(LayoutInflater.java:353) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:319) at android.app.Activity.setContentView(Activity.java:1973) at com.mysliderapp.MainActivity.onCreate(MainActivity.java:99) at android.app.Activity.performCreate(Activity.java:5275) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)  at android.app.ActivityThread.access$800(ActivityThread.java:142)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5118)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)  at dalvik.system.NativeStart.main(Native Method)  Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.SlidingLayer" on path: DexPathList[[zip file "/data/app/com.mysliderapp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.mysliderapp-2, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at android.view.LayoutInflater.createView(LayoutInflater.java:559) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:319)  at android.app.Activity.setContentView(Activity.java:1973)  at com.mysliderapp.MainActivity.onCreate(MainActivity.java:99)  at android.app.Activity.performCreate(Activity.java:5275)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)  at android.app.ActivityThread.access$800(ActivityThread.java:142)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5118)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)  at dalvik.system.NativeStart.main(Native Method)

最佳答案

在 XML 布局中将 SlidingLayer 更改为 com.wunderlist.slidinglayer.SlidingLayer

当使用外部组件时,Android Studio 通常会在仅通过名称扩展组件时遇到问题,因此您需要提供完整的包名称。

<com.wunderlist.slidinglayer.SlidingLayer
android:id="@+id/slidingLayer1"
android:layout_width="match_parent"
android:layout_height="@dimen/layer_height"
android:elevation="2dip"
android:layout_above="@+id/linearLayout"
android:layout_alignParentStart="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_light">

<WebView
android:id="@+id/authWebView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:drawablePadding="15dip"
android:paddingBottom="80dp"
android:textSize="17sp"
android:textColor="@color/primary_text"/>

<Button
android:id="@+id/buttonClose"
style="@style/ButtonRed"
android:onClick="buttonClicked"
android:layout_marginBottom="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/close_button_container"/>
</RelativeLayout>
</com.wunderlist.slidinglayer.SlidingLayer>

关于Android slider 库在包含到我的应用程序时崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33942906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com