【问题标题】:Error in activity_main.xml after creating a new project创建新项目后activity_main.xml 中的错误
【发布时间】:2018-06-10 06:45:32
【问题描述】:

我创建了一个新项目,构建完成后,当我尝试打开 activity_main.xml 时,出现以下渲染错误:

谁能告诉,这背后的可能原因是什么以及如何解决这个问题?我刚开始学习 android ,但一开始我就卡住了。

按照要求,添加我的应用程序的 build.gradle 和 layout.xml :

Build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "28.0.0"
    defaultConfig {
        applicationId "com.chanfool21.firstapp"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:27.+'
    testCompile 'junit:junit:4.12'
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    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"
    tools:context="com.chanfool21.firstapp.MainActivity">

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

【问题讨论】:

  • 你查看过这个SO 吗?
  • 你用的是哪个android studio
  • @WahdatKashmiri Android Studio 2.2.1
  • @Chanfool21 更新到最新版本再检查

标签: android android-studio rendering


【解决方案1】:

如果这不起作用,只需进行 gradle 构建清理/重建项目,如果也不起作用,则使缓存重启无效

【讨论】:

  • 您好 Himel,我按照您的建议执行了所有步骤,但仍然无法正常工作,显示相同的错误消息。空指针异常和其他消息与上图相同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-12
相关资源
最近更新 更多