I have posted the HandlerThread class where I got an error on the following line:
private final static String TAG_LOG = MainAct.TAG_LOG + "->" + RoomPersistentDBHandlerThread.class.getSimpleName();
The error was inner class cant have inner static memedeclartion
.
Can any of you explain to me why for the aforementioned line of code, I could not declare static variable inside the inner class, despite in the immediate following line, the static variable has no errors.
thanks
code:
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
}