gpt4 book ai didi

Android 的 Java 错误 "Unable to Find Symbol"

转载 作者:行者123 更新时间:2023-12-02 00:10:20 24 4
gpt4 key购买 nike

所以我尝试制作一个 Android 应用程序,但是当我尝试编译我的项目时,出现错误:

DisplayMessageActivity.java :2 :Error - cannot find symbol
"public class DisplayMessageActivity extends Activity {"

symbol: class Activity

这是我的 DisplayMessageActivity.java 源代码(它的父级是 MainActivity.java,它导入 android.app.Activity 和 android.os.Bundle 包):

public class DisplayMessageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);

// Set the text view as the activity layout
setContentView(textView);
}
}

这是 AndroidManifest.xml 文件 -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.HelloWorld"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@android:style/Theme.Holo">
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="@string/title_activity_display_message">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android.value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>

请帮忙,

尼罗56

最佳答案

您需要在包声明后在文件顶部将 Activity 作为 import android.app.Activity 导入。

关于Android 的 Java 错误 "Unable to Find Symbol",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12945927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com