为了账号安全,请及时绑定邮箱和手机立即绑定

XML 文件无法引用类文件

XML 文件无法引用类文件

至尊宝的传说 2023-02-16 15:35:11
大约一周前,android studio 几乎破坏了我编写的所有代码,因为某些关键问题在网上找不到太多。我试图找到一个解决方案的是 xml 文件,无论是 AndroidManifest.xml 文件还是活动文件都在类上出错。我尝试使用 alt+enter 并让它通过创建一个与已经存在的文件同名的新文件来自动修复它,并且在不到一秒钟的时间内,错误消失只会再次出错。我已经重新安装了 android studio,试图查看我是否以某种方式损坏了文件。我写的唯一代码是 2 个按钮。因此,除非我做错了什么,否则我不确定类中的代码是如何导致这种情况的。在“tools:context”字段下,它在文件上出错,指出无法识别类文件(在 xml 文件中)。主要活动:import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    public void Options_Button1(View view) {        Intent option = new Intent(MainActivity.this,Options.class);        startActivity(option);    }    public void Add_Button1(View view){        Intent add = new Intent(MainActivity.this,placeholder.class);        startActivity(add);    }}活动 xml 文件:<?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">    <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginStart="16dp"        android:layout_marginTop="16dp"        android:clickable="true"        android:focusable="true"        android:onClick="Options_Button1"        android:text="@string/options6"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent" />
查看完整描述

1 回答

?
繁花不似锦

TA贡献1851条经验 获得超4个赞

解决方案如上文评论所述,通过 file=>invalidates Caches/Restart 清除缓存文件。



查看完整回答
反对 回复 2023-02-16
  • 1 回答
  • 0 关注
  • 58 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信