如何调用具有“context mContext”的方法

时间:2017-07-11 04:56:15

标签: java android parameters

我在调用此方法时遇到了麻烦:

public void loadArray(Context mContext) {
    SharedPreferences mSharedPreference1 = PreferenceManager.getDefaultSharedPreferences(mContext);
    WorkList.clear();
    int size = mSharedPreference1.getInt("Status_size", 0);
    for (int i = 0; i < size; i++) {
        WorkList.add(mSharedPreference1.getString("Status_" + i, null));
    }
}

我正在尝试在启动应用程序时加载已保存的数据。 我试着打电话给loadArray(MainActivity.this);并得到了这个:

> Information:Gradle tasks [:app:assembleDebug]
/Users/Long/AndroidStudioProjects/Hello/app/src/main/java/com/newthingtank/along/hello/MainActivity.java
Error:(33, 5) error: invalid method declaration; return type required
Error:(33, 24) error: type annotations are not supported in -source 1.7
(use -source 8 or higher to enable type annotations)
Error:(33, 28) error: <identifier> expected
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 3.598 secs
Information:4 errors
Information:0 warnings
Information:See complete output in console

0 个答案:

没有答案