0

我已经发布了 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

}
4

0 回答 0