非静态类不能具有静态变量

时间:2018-12-11 14:55:35

标签: android inner-classes android-handlerthread

我将HandlerThread类发布到了以下行:

private final static String TAG_LOG = MainAct.TAG_LOG + "->" + RoomPersistentDBHandlerThread.class.getSimpleName();

错误是inner class cant have inner static memedeclartion

任何人都可以向我解释为什么对于上述代码行,我无法在 内部类,尽管紧接在下一行,静态变量也没有错误。

谢谢

代码

class MainAct {

public void buildPersistentDB() {

}


private class RoomPersistentDBHandlerThread extends HandlerThread implements Handler.Callback {
    private final static String TAG_LOG = MainAct.TAG_LOG + "->" + RoomPersistentDBHandlerThread.class.getSimpleName();
    private final static String THROW_ON_LOOPER_NOT_INITIALIZED = "LOOPER_NOT_INITIALIZED";
    private WeakReference<Context> mWeakReferenceToActMain;
    private Handler mHandler = null;
    private final static String markerAstrisks = "++++++++++++++++++++++++ ";

    public RoomPersistentDBHandlerThread(String name, Context context) {
        super(name);
        Log.w(TAG_LOG, "RoomPersistentDBHandlerThread constructor is called.");
        this.mWeakReferenceToActMain = new WeakReference<>(context);
    }

    @Override
    protected void onLooperPrepared() {
        super.onLooperPrepared();
        Log.w(TAG_LOG, "onLooperPrepared is called.");
        Log.v(TAG_LOG, markerAstrisks + " [getLooper: " + this.getLooper() + "] " + markerAstrisks);

        try {
            this.mHandler = Optionals.toOptional(this.getLooper())
                    .map(looper -> new Handler(looper, this))
                    .orElseThrow(() -> new NullPointerException(THROW_ON_LOOPER_NOT_INITIALIZED));
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }//eof catch
    }//eof onLooperPrepared

    public void enqueueMessage(int what) {
        Log.w(TAG_LOG, "enqueueMessage is called for what = " + what);
        this.mHandler.sendEmptyMessage(what);
    }

    @Override
    public boolean handleMessage(Message msg) {
        Log.w(TAG_LOG, "handleMessage is called for msg.what = " + msg.what);

        switch(msg.what) {
            case WHAT_MSG_INIT_PERSISTENT_DATABASE:
                mWeakReferenceToActMain.get()
                break;
        }
        return true;
    }
}//eof-RoomPersistentDBHandlerThread

}

0 个答案:

没有答案