在Android中导入包类时非法前向引用

时间:2019-04-02 16:35:59

标签: android

正如标题所暗示的那样,我已经看到了非法正向引用,它们已经属于Java代码。但就我而言,我在软件包导入中遇到了问题。一切都很好,但是突然我不知道Android Studio发生了什么,它开始向我显示错误以下信息

error: illegal forward reference

当我检查Java编译器下Android Studio的构建区域并双击错误后,我进入了下面打包的import语句。

import com.abacusoft.util.AppController;

其中缺少或存在什么错误?有帮助吗?

我的AppController类扩展了如下所述的Application类

public class AppController extends Application

编辑:以下是我完整的AppController类

package com.abacusoft.util;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.abacusoft.services.CallReceivingService;
import com.android.volley.Request;
import com.android.volley.RequestQueue; 
import com.android.volley.toolbox.Volley;

public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();

private RequestQueue mRequestQueue;
private static SharedPreferences preferences;

private static AppController mInstance;
private boolean isAppRunningFirstTime = true;

@Override
public void onCreate() {
    super.onCreate();
    mInstance = this;
    preferences = this.getSharedPreferences(AppSharedPref.APP_PREFS, Context.MODE_PRIVATE);

}

@Override
public void onTerminate() {
    super.onTerminate();
    stopService(new Intent(getApplicationContext(), CallReceivingService.class));
}

public static synchronized AppController getInstance() {
    return mInstance;
}

//Get Shared Preference
public SharedPreferences getPreferences() {
    return preferences;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}


public <T> void addToRequestQueue(Request<T> req, Object tag) {
    req.setTag(tag);
    getRequestQueue().add(req);

}

public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
    if (mRequestQueue != null) {
        mRequestQueue.cancelAll(tag);
    }
}

public boolean isAppRunningFirstTime() {
    return isAppRunningFirstTime;
}

public void setAppRunningFirstTime(boolean appRunningFirstTime) {
    isAppRunningFirstTime = appRunningFirstTime;
}

}

1 个答案:

答案 0 :(得分:0)

您可能不是在类上而是在要创建的实例上调用AppController.getInstance

应该是AppController appController=appController.getinstance()之类的

AppController appController=AppController.getinstance()

大写字母A