我昨天开始使用Android Studio,并按照教程制作了一个简单的应用程序,没什么特别的。该项目进展顺利,我正在测试每几个步骤,一切都很好。
无处不在,当我再次进行测试(我只是添加了一个按钮)时,该应用程序不再想要运行。该错误说了类似“找不到符号button_first”的内容,我将其按钮的ID更改为random_button,然后按照教程将整个代码重构为该按钮。它还说错误发生在第26行,而文件只有7行。
因此,我决定制作一个新项目,然后重新做一遍。我意识到的是,某些文件已更改。例如,这是AndroidManifest.xml的外观以及在新项目中的外观:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.inventorymanagement">
<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我原始项目中相同文件的外观:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E4D86B"
tools:context=".FirstFragment">
<TextView
android:id="@+id/textview_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:fontFamily="cursive"
android:text="@string/hello_first_fragment"
android:textColor="@android:color/white"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
还有许多其他文件以这种方式进行了更改,而我完全没有碰过它们。
当我尝试使用基本布局运行新项目时,什么都没有做,这给了我一个错误,提示"No basic activity"
,并且不想运行。而现在,又一次我没有改变任何事情,这给了我一个不同的错误:
C:\Users\Em\AndroidStudioProjects\InventoryManagement\app\src\main\res\mipmap-anydpi-v26\ic_launcher.xml:11: AAPT: error: unclosed token.
问题文件再次更改并切断。
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidLayouts">
<shared>
<config>
<device id="pixel" />
<device id="pixel_3_xl" />
<device id="pixel_3" />
</config>
</shared>
</comp
有人知道如何解决此问题,还是应该重新安装Android Studio并重新开始?