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

时间:2015-01-01 17:05:16

标签: android compiler-errors

错误:

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

1 个答案:

答案 0 :(得分:2)

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

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