大約一周前,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" />
添加回答
舉報
0/150
提交
取消