gpt4 book ai didi

android - 如何使用它创建一个扩展 Application 并覆盖其 onCreate() 方法的类

转载 作者:行者123 更新时间:2023-12-02 11:15:36 25 4
gpt4 key购买 nike

错误:

Application cannot be resolved to a type

SharedPreferences cannot be resolved to a type`

the method override must override or implement a super type method

Multiple markers at this line

PreferenceManager cannot be resolved

程序:
 package com.su.vapour;

public class Common extends Application {

public static String[] email_arr;
private static SharedPreferences prefs;

@Override
public void onCreate() {
super.onCreate();
prefs = PreferenceManager.getDefaultSharedPreferences(this);

List<String> emailList = getEmailList();
email_arr = emailList.toArray(new String[emailList.size()]);
}

private List<String> getEmailList() {
List<String> lst = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
lst.add(account.name);
}
}
return lst;
}
}

最佳答案

您需要添加import您在此 Java 文件中引用的类和接口(interface)的语句,例如 android.app.Applicationandroid.content.SharedPreferences .
import语句是一个相当基本的 Java 概念。我强烈建议你去学习 Java,尤其是 key areas Android应用程序开发所需的。

关于android - 如何使用它创建一个扩展 Application 并覆盖其 onCreate() 方法的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27732808/

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