2017-10-17 58 views
1

我最近下载了Android Studio并尝试打开一个新项目。所生成看起来像这样的代码:无法在Android Studio中打开新程序

package com.example.trevo.myapplication; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 

public class GettingStarted extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_getting_started); 
    } 
} 

在我的屏幕顶部的选项卡(SCR,主,JAVA,COM,例如,trevo,所有MyApplication,GettingStarted)都以红色下划线。此外,行setContentView(R.layout.activity_getting_started);中的'R'是红色,并且出现“无法解析符号”的错误。当我尝试按程序运行程序时,出现以下错误。

C:\Users\trevo\Documents\Java4Android_Projects\MyApplication\app\src\main\res\layout\activity_getting_started.xml 

Error:(13, 49) String types not allowed (at 'layout_constraintBottom_toBottomOf' with value 'parent'). 

Error:(14, 45) String types not allowed (at 'layout_constraintLeft_toLeftOf' with value 'parent'). 

Error:(15, 47) String types not allowed (at 'layout_constraintRight_toRightOf' with value 'parent'). 

Error:(16, 43) String types not allowed (at 'layout_constraintTop_toTopOf' with value 'parent'). 

Error:Execution failed for task ':app:processDebugResources'. 
> com.android.ide.common.process.ProcessException: Failed to execute aapt 
Information:BUILD FAILED 

有没有其他人有Android Studio的这个问题?我能做些什么来弥补这些错误?

+0

只需清理并通过工具栏上的生成选项重新生成。 –

回答

1

这是Android Studio中的一个已知错误,也发生在我的构建中。

要解决这个问题,清理生成项目,并删除其中有[R在它的进口,Android的Studio将随后导入正确[R

这个问题似乎在最新的3.0 RC版本得到解决

+0

我该如何删除其中含有R的导入? – user8735495

+0

只需删除该行,Android Studio将自动添加正确的行。如果它没有导入,那么当错误显示时,只需按alt + return键,它将显示所有R的列表,然后只需选择正确的导入 – Rinav