【问题标题】:how To use it create a class that extends Application and override its onCreate() method如何使用它创建一个扩展 Application 并覆盖其 onCreate() 方法的类
【发布时间】:2015-01-01 17:05:16
【问题描述】:

错误:

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;
    }  
}

【问题讨论】:

  • 好像你没有导入android.app.Application。你懂一点Java吗?
  • 我只知道 java littlebit 基础

标签: android compiler-errors


【解决方案1】:

您需要为您在此 Java 文件中引用的类和接口添加 import 语句,例如 android.app.Applicationandroid.content.SharedPreferences

import 语句是一个相当基本的 Java 概念。我强烈建议您去学习 Java,尤其是 Android 应用开发所需的 key areas

【讨论】:

    猜你喜欢
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多