2

当我编译我的 apk 时,“运行”apk 时出现错误,这是:

java.lang.RuntimeException: Unable to start activity        
ComponentInfo{com.robsie.quiz/com.robsie.quiz.SplashActivity}:    
android.view.InflateException: Binary XML file line #7: Error inflating class 
android.support.v4.view.ViewPager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5202)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating     
class android.support.v4.view.ViewPager
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
at android.app.Activity.setContentView(Activity.java:1885)
at com.robsie.quiz.SplashActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5108)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2263)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class     
"android.support.v4.view.ViewPager" on path: /data/app/com.robsie.quiz-1.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
... 21 more

但是当我从 Android Studio 打开它时,如果先是“重建项目”,然后是“运行”,我不会得到任何信息。如果只有“运行”,我会收到此错误。

java: can not find symbol
symbol: Variable layout
location: class com.robsie.quiz.R

我正在使用 CirclePageIndicator .. 这是我的“build.gradle”

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
    compile files('libs/android-support-v4.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':C::Users:shekel:Desktop:WorkSpace:library')

}

android {
    compileSdkVersion 11
    buildToolsVersion "17.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }
}
4

3 回答 3

1

您的错误指出:

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.ViewPager"

您的 gradle 构建配置将其显示为依赖项,但您可能需要检查模块指向支持库的路径的位置。

Android Studio 很可能无法检测到您的支持库不可用,因此您可以编译,但看到应用程序失败。

于 2013-06-25T19:16:50.400 回答
0

我有同样的错误信息。

为了使用带有可滑动标签的操作栏(ViewPager)构建活动

我所做的是:更新到最新的 Android 版本(当前 0.4.4)

在打开新项目向导中,选择导航类型:

操作栏选项卡(带有 ViewPager)如下

在此处输入图像描述

于 2014-02-09T13:23:23.867 回答
0

好吧,我没有使用过 Android Studio,但对我来说,它看起来像是 ADT 的一个已知错误,您必须在其中明确标记要导出的外部库,这个答案显示了它在 Eclipse 中的工作原理。

于 2013-06-25T19:18:32.980 回答