【问题标题】:Android Studio activity not linkingAndroid Studio 活动未链接
【发布时间】:2020-08-26 18:44:57
【问题描述】:

我正在 Android Studio 中为我的应用制作登录屏幕。

我的MainActivity.java 中有这个:

Intent intent = new Intent(MainActivity.this, NewAccountActivity.class);
startActivity(intent);


这在我的NewAccountActivity.java

public class NewAccountActivity extends AppCompatActivity {

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


还有我的activity_new_account.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>


但是...它给了我来自NewAccountActivity.java 的错误:Cannot resolve symbol 'activity_new_account'


有谁知道如何解决这个问题,我已经用谷歌搜索了半个小时,仍然没有答案。

【问题讨论】:

  • 您是否在运行应用程序后或编译代码时遇到此错误?
  • 尝试清理和重建项目(在“构建”菜单下),如果这不起作用,则使缓存无效/重新启动(在“文件”下)。具有新创建布局的最新 Android 版本存在故障。

标签: java android-studio android-activity


【解决方案1】:

在当前的最新更新之后,您经常会收到此类错误。 为了修复,请尝试以下步骤(对我有用):

从菜单中点击文件

点击无效缓存/重启

现在,等待 android studio 重启并重建。

你的问题应该解决了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 2016-05-09
    • 2021-06-24
    • 2011-10-18
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    相关资源
    最近更新 更多