You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio无法初始化ConstraintLayout及MainActivity未解析问题求助

Android Studio 3.3.1: ConstraintLayout Instantiation Error & Unresolved MainActivity Class

我是Android Studio的新手,最近碰到了几个棘手的问题,已经尝试过清除缓存、清理/重建项目,但问题还是没解决。我的环境是Windows系统,Android Studio版本为3.3.1,Gradle版本为4.10.1,希望大家能帮忙看看怎么处理。

问题1:ConstraintLayout无法实例化

右上角缩放按钮旁边出现了蓝色警告,提示无法初始化一个或多个类,其中android.support.constraint.ConstraintLayout无法实例化,具体异常信息如下:

java.lang.NoClassDefFoundError: android/support/constraint/R$styleable
android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:599)
android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:576)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
android.view.LayoutInflater.inflate(LayoutInflater.java:492)
android.view.LayoutInflater.inflate(LayoutInflater.java:394)

问题2:Unresolved class MainActivity

在activity_main.xml的文本模式下,tools:context=".MainActivity"这一行的.MainActivity标红,编辑器提示“Unresolved class MainActivity”。该文件的完整代码如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

问题3:我的AndroidManifest.xml内容

附上我的AndroidManifest.xml文件内容,供大家参考:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kaan.asd">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

内容的提问来源于stack exchange,提问作者user9427949

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 03:53:58