Android Studio支持Lib SlidePanel

时间:2013-10-22 13:03:04

标签: android android-layout android-studio

我正在尝试在android studio中制作简单的SlidingPanel。 我在SDK管理器中下载了存储库(Google和支持),并通过添加以下行编辑了gradle文件:

compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:18.0.+'

Libs在项目中可见。 我还添加了一个布局:

<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">
<include layout="@layout/fragment_menu_panel" android:layout_height="match_parent" android:layout_width="wrap_content"/>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff333333" >

        <WebView
            android:id="@+id/content_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />
    </RelativeLayout>

</android.support.v4.widget.SlidingPaneLayout>

它在IDE中呈现得相当不错,但是当我尝试在设备上运行此应用程序时,它会因以下错误而崩溃:

10-22 14:54:03.633  11099-11099/com.example.myapplication2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myapplication2/com.example.myapplication2.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication2.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myapplication2-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myapplication2-1, /vendor/lib, /system/lib]]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
        at android.app.ActivityThread.access$600(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication2.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myapplication2-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myapplication2-1, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)

问题就我看到该库没有附加到apk。我该如何解决?

1 个答案:

答案 0 :(得分:1)

这是一个非常奇怪的问题,无论如何修复了构建 - &gt;重建项目。 所以除了Android Studio之外,每件事都很好。