创建新项目后activity_main.xml中的错误 [英] Error in activity_main.xml after creating a new project

查看:51
本文介绍了创建新项目后activity_main.xml中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a new project and after build is done, when I tried opening activity_main.xml it is giving me following Rendering error:

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

Can anyone tell, what's the possible reason behind this and how to solve this problem? I have just started learning android , but in the very beginning I am getting stuck.

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

As asked, adding my app's build.gradle and layout.xml :

Build.gradle:

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:

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>

推荐答案

如果这不起作用,就做一个 gradle build 清理/重建项目,如果它也不起作用,则缓存重启无效

just do a gradle build if that doesn't work clean/rebuild project if also that dosen't work invalidate cach restart

这篇关于创建新项目后activity_main.xml中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆