【问题标题】:Android Studio Rendering Error after project builds项目构建后的 Android Studio 渲染错误
【发布时间】:2016-02-24 11:20:52
【问题描述】:

编辑

我使用 E-Clips 作为我的 IDE 来开发安卓程序。 我打算迁移到 Android Studio,所以我对这个 IDE 真的很陌生。

安装 Android Studio 后,当我尝试创建新项目时,我选择 API 15 (android 4.0.3) 并为 Activity Page 我选择空白主题。

当项目打开并 gradle 完成同步时,设计选项卡上的 XML 页面不显示任何内容并且没有错误。

在我将渲染目标更改为 API 15 后,出现以下消息:

这是我的 xml 文件中的内容,请注意我在创建项目时没有更改默认代码。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout       xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="test.apptune.ir.stack.MainActivity"
tools:showIn="@layout/activity_main">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!" />
    </RelativeLayout>

这是我的 biuld.gradle :

    apply plugin: 'com.android.application'

    android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "test.apptune.ir.stack"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
    }

    dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
    }

如果您在这方面帮助我,我将不胜感激。

【问题讨论】:

  • 添加您的 build.gradle... 您缺少的一些库

标签: android xml android-studio layout


【解决方案1】:

Pouya Heydari...在 Gradle 脚本中的 build.gradle(Module:app) 中添加 android 支持设计库

repositories {
mavenCentral()
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.0'
}

**确保您已使用 SDK 管理器(工具->ANdroid->SDk 管理器-> Extras-> Android 支持库)下载了 Android 支持库。

然后重建项目。谢谢

【讨论】:

  • 亲爱的 Vishal Chauhan 感谢您的回复。我在上面添加了几行,错误变为:无法实例化以下类:-android.support.design.widget.AppBarLayout。异常细节是:Java.lang.NullPointerException
  • Pouya.. 我已经更新了我的答案。请检查这个。
【解决方案2】:

更改 res/values/styles.xml 中的 AppTheme 父级以解决此问题。替换

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

我希望这能解决您的问题。谢谢...

【讨论】:

  • 将渲染目标从API 15更改为API 22(或者Android SDK(您安装的API版本)),然后构建项目......
  • 正如我在问题中提到的,当我将目标设置为 API 22 时,“设计”选项卡不显示任何内容。(没有模拟器)
猜你喜欢
  • 2020-08-23
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-24
相关资源
最近更新 更多