问:
App crashing while calling callback() to java. Getting runtime error due to detatchThread
I am trying to basically create a callback from native-lib.cpp class callback() method to call some method in java. But for that, I need env variable also. I am trying to create same in native-lib.cpp but getting this error.  I think some issue because of thread being detatched. Can someone please clarify this. I am very new to callbacks creation concept. Can someone point out exactly the issue. Some issue with detachThread seems to me. Can someone clarify on the issue. Thanks in advance.

This  is the native-lib.cpp:

```<code>#include <jni.h>
#include <string>
#include "Numbers.h"

#include <android/log.h>

#define  LOG_TAG    "logs"

#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

typedef struct number_ctx{
    JavaVM  *javaVM;
    jclass   mathsClass;
    jobject  mathsObj;
    jclass   mainActivityClass;
    jobject  mainActivityObj;
    pthread_mutex_t  lock;
} NumbersCtx;
NumbersCtx g_ctx;

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
    JNIEnv* env;
    memset(&g_ctx, 0, sizeof(g_ctx));

    g_ctx.javaVM = vm;

    if (vm ->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
        return JNI_ERR; // JNI version not supported.
    }

    jclass  clz = env->FindClass(
            "com/example/maths/Maths1");

    g_ctx.mathsClass = static_cast<jclass>(env->NewGlobalRef(clz));

    clz = env->FindClass(
            "com/example/maths/MainActivity");

    g_ctx.mainActivityClass = static_cast<jclass>(env->NewGlobalRef(clz));

    g_ctx.mathsObj = NULL;
    g_ctx.mainActivityObj = NULL;

    env->DeleteLocalRef(clz);

    return  JNI_VERSION_1_6;
}

void callback() {

    JNIEnv* env;

    LOGD("Starting finally ");

    if (g_ctx.javaVM ->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
        LOGD("JNI Error is %d" , JNI_ERR); // JNI version not supported.
    }

    LOGD("Env variable received successfully");

    int status = g_ctx.javaVM->AttachCurrentThread(&env, NULL);

    if(status != JNI_OK) {
        LOGD("Failed to attach the thread");
    } else {

        LOGD("Thread attached successfully");

        jmethodID testMessage = env->GetMethodID(g_ctx.mathsClass, "printMessage",
                                                 "()V");
        // Call the method on the object
        env->CallVoidMethod(g_ctx.mathsObj, testMessage);

        if (env->ExceptionCheck()) {
            env->ExceptionDescribe();
        }

        LOGD("Void Method called Successfully");

        g_ctx.javaVM->DetachCurrentThread();

        LOGD("Thread detached successfully");
    }

    LOGD("This callback is called finally");
}

jfieldID getPtrFieldId(JNIEnv * env, jobject obj)
{
    static jfieldID ptrFieldId = 0;

    if (!ptrFieldId)
    {
        jclass c = env->GetObjectClass(obj);
        ptrFieldId = env->GetFieldID(c, "numberptr", "J");
        env->DeleteLocalRef(c);
    }

    return ptrFieldId;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_example_maths_Maths1_createNumberInstance(JNIEnv *env, jobject thiz, jint a, jint b) {
    // TODO: implement createNumberInstance()

    g_ctx.mathsObj = env->NewGlobalRef(thiz);
    Numbers* num = new Numbers(a, b);
    callback();
    env->SetLongField(thiz, getPtrFieldId(env, thiz), (jlong) num);

}
</code>```

This is error which I am getting:

```2020-06-02 19:25:39.101 15965-15965/com.example.maths A/m.example.math: runtime.cc:2067] Thread[1,tid=15965,Native,Thread*=0xec991800,peer=0x71b391f0,"main"] attempting to detach while still running code
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] Runtime aborting...
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] Dumping all threads without mutator lock held
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] All threads:
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] DALVIK THREADS (17):
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "main" prio=10 tid=1 Runnable
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=0 dsCount=0 flags=0 obj=0x71b391f0 self=0xec991800
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | sysTid=15965 nice=-10 cgrp=default sched=0/0 handle=0xece36dc8
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | state=R schedstat=( 466154407 353144186 350 ) utm=12 stm=34 core=0 HZ=100
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | stack=0xff27a000-0xff27c000 stackSize=8192KB
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | held mutexes= "abort lock" "mutator lock"(shared held)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #00 pc 00493b43  /apex/com.android.runtime/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, int, BacktraceMap*, char const*, art::ArtMethod*, void*, bool)+115)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #01 pc 005b1fd2  /apex/com.android.runtime/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+994)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #02 pc 005ace61  /apex/com.android.runtime/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+65)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #03 pc 005d2cd1  /apex/com.android.runtime/lib/libart.so (art::DumpCheckpoint::Run(art::Thread*)+929)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #04 pc 005cac06  /apex/com.android.runtime/lib/libart.so (art::ThreadList::RunCheckpoint(art::Closure*, art::Closure*)+486)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #05 pc 005c9e6c  /apex/com.android.runtime/lib/libart.so (art::ThreadList::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool)+2268)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #06 pc 005796f0  /apex/com.android.runtime/lib/libart.so (art::AbortState::DumpAllThreads(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, art::Thread*) const+448)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #07 pc 00564d30  /apex/com.android.runtime/lib/libart.so (art::Runtime::Abort(char const*)+1536)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #08 pc 000249b3  /apex/com.android.runtime/lib/libartbase.so (_ZNSt3__110__function6__funcIPFvPKcENS_9allocatorIS5_EES4_EclEOS3_+35)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #09 pc 0000bac7  /system/lib/libbase.so (android::base::LogMessage::~LogMessage()+727)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #10 pc 005645de  /apex/com.android.runtime/lib/libart.so (art::Runtime::DetachCurrentThread()+414)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #11 pc 003ecc83  /apex/com.android.runtime/lib/libart.so (art::JII::DetachCurrentThread(_JavaVM*)+67)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #12 pc 003e3445  /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::CheckJII::DetachCurrentThread(_JavaVM*)+117)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #13 pc 00009d6a  /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/lib/x86/libnative-lib.so (_JavaVM::DetachCurrentThread()+42)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #14 pc 00009a8a  /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/lib/x86/libnative-lib.so (callback()+554)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #15 pc 0000a24c  /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/lib/x86/libnative-lib.so (Java_com_example_maths_Maths1_createNumberInstance+172)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #16 pc 00144f67  /apex/com.android.runtime/lib/libart.so (art_quick_generic_jni_trampoline+71)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #17 pc 0013e7d2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub+338)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #18 pc 00149a69  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+281)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #19 pc 00332502  /apex/com.android.runtime/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+386)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #20 pc 0032c19c  /apex/com.android.runtime/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+988)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #21 pc 006818dd  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+989)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #22 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #23 pc 0011dc02  [anon:dalvik-classes.dex extracted in memory from /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/base.apk] (com.example.maths.Maths1.<init>+26)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #24 pc 0068461c  /apex/com.android.runtime/lib/libart.so (MterpInvokeDirect+1324)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #25 pc 00138921  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_direct+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #26 pc 0011db02  [anon:dalvik-classes.dex extracted in memory from /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/base.apk] (com.example.maths.MainActivity.onCreate+26)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #27 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #28 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #29 pc 0019175e  /system/framework/framework.jar (android.app.Activity.performCreate+30)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #30 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #31 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #32 pc 00191726  /system/framework/framework.jar (android.app.Activity.performCreate+2)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #33 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #34 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #35 pc 001eefda  /system/framework/framework.jar (android.app.Instrumentation.callActivityOnCreate+6)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #36 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #37 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #38 pc 00180bb8  /system/framework/framework.jar (android.app.ActivityThread.performLaunchActivity+752)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #39 pc 0068461c  /apex/com.android.runtime/lib/libart.so (MterpInvokeDirect+1324)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #40 pc 00138921  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_direct+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #41 pc 00180836  /system/framework/framework.jar (android.app.ActivityThread.handleLaunchActivity+94)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #42 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #43 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #44 pc 0025e28e  /system/framework/framework.jar (android.app.servertransaction.LaunchActivityItem.execute+126)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #45 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #46 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #47 pc 002607da  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.executeCallbacks+154)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #48 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #49 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #50 pc 00260716  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.execute+146)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #51 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #52 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #53 pc 0017fb6e  /system/framework/framework.jar (android.app.ActivityThread$H.handleMessage+78)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #54 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #55 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #56 pc 002f5846  /system/framework/framework.jar (android.os.Handler.dispatchMessage+38)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #57 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #58 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #59 pc 00319ee6  /system/framework/framework.jar (android.os.Looper.loop+466)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #60 pc 00684fdc  /apex/com.android.runtime/lib/libart.so (MterpInvokeStatic+1260)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #61 pc 001389a1  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_static+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #62 pc 00189466  /system/framework/framework.jar (android.app.ActivityThread.main+194)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #63 pc 002f8e0a  /apex/com.android.runtime/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.1175793267244191248+298)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #64 pc 002ffcc5  /apex/com.android.runtime/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*)+181)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #65 pc 0066fc49  /apex/com.android.runtime/lib/libart.so (artQuickToInterpreterBridge+1209)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #66 pc 0014503d  /apex/com.android.runtime/lib/libart.so (art_quick_to_interpreter_bridge+77)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #67 pc 0013e9a2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+418)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #68 pc 00149a7a  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+298)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #69 pc 0055a563  /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+99)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #70 pc 0055c37f  /apex/com.android.runtime/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned int)+1327)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #71 pc 004c91a3  /apex/com.android.runtime/lib/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+83)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.example.maths.Maths1.createNumberInstance(Native method)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.example.maths.Maths1.<init>(Maths1.java:16)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.example.maths.MainActivity.onCreate(MainActivity.java:21)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "Runtime worker thread 0" prio=10 tid=2 Native (still starting up)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=1 dsCount=0 flags=1 obj=0x0 self=0xd9500000
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | sysTid=15991 nice=0 cgrp=default sched=0/0 handle=0xec77fd90
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | state=S schedstat=( 1604515 798906 8 ) utm=0 stm=0 core=1 HZ=100
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | stack=0xec771000-0xec773000 stackSize=63KB
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | held mutexes=
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   kernel: (couldn't read /proc/self/task/15991/stack)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #00 pc 00000b77  [vdso] (__kernel_vsyscall+7)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #01 pc 00092328  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #02 pc 00150802  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+114)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #03 pc 00150783  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::Wait(art::Thread*)+35)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #04 pc 005d4b15  /apex/com.android.runtime/lib/libart.so (art::ThreadPool::GetTask(art::Thread*)+261)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #05 pc 005d3c43  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Run()+83)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #06 pc 005d370f  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Callback(void*)+239)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #07 pc 0011a8e5  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #08 pc 000af6a7  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   (no managed stack frames)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "Jit thread pool worker thread 0" prio=10 tid=3 Native
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=1 dsCount=0 flags=1 obj=0x159c0030 self=0xec98ee00
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | sysTid=15990 nice=0 cgrp=default sched=0/0 handle=0xd9404d90
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | state=S schedstat=( 4160010 1789692 15 ) utm=0 stm=0 core=1 HZ=100
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | stack=0xd9306000-0xd9308000 stackSize=1023KB
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | held mutexes=
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   kernel: (couldn't read /proc/self/task/15990/stack)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #00 pc 00000b77  [vdso] (__kernel_vsyscall+7)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #01 pc 00092328  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #02 pc 00150802  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+114)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #03 pc 00150783  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::Wait(art::Thread*)+35)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #04 pc 005d4b15  /apex/com.android.runtime/lib/libart.so (art::ThreadPool::GetTask(art::Thread*)+261)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #05 pc 005d3c75  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Run()+133)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #06 pc 005d370f  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Callback(void*)+239)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #07 pc 0011a8e5  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #08 pc 000af6a7  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   (no managed stack frames)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "Runtime worker thread 1" prio=10 tid=4 Native (still starting up)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=1 dsCount=0 flags=1 obj=0x0 self=0xd9508c00
```

答:
If GetEnv returns JNI_OK, the current thread is already attached and you should not try to detach it.

This is why Android is screaming bloody murder at you: you are trying to detach the main thread!

You should only try to attach (and detach later) if it returned JNI_EDETACHED.

Body:
I am trying to basically create a callback from native-lib.cpp class callback() method to call some method in java. But for that, I need env variable also. I am trying to create same in native-lib.cpp but getting this error.  I think some issue because of thread being detatched. Can someone please clarify this. I am very new to callbacks creation concept. Can someone point out exactly the issue. Some issue with detachThread seems to me. Can someone clarify on the issue. Thanks in advance.

This  is the native-lib.cpp:

#include <jni.h>
#include <string>
#include "Numbers.h"

#include <android/log.h>

#define  LOG_TAG    "logs"

#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

typedef struct number_ctx{
    JavaVM  *javaVM;
    jclass   mathsClass;
    jobject  mathsObj;
    jclass   mainActivityClass;
    jobject  mainActivityObj;
    pthread_mutex_t  lock;
} NumbersCtx;
NumbersCtx g_ctx;

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
    JNIEnv* env;
    memset(&g_ctx, 0, sizeof(g_ctx));

    g_ctx.javaVM = vm;

    if (vm ->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
        return JNI_ERR; // JNI version not supported.
    }

    jclass  clz = env->FindClass(
            "com/example/maths/Maths1");

    g_ctx.mathsClass = static_cast<jclass>(env->NewGlobalRef(clz));

    clz = env->FindClass(
            "com/example/maths/MainActivity");

    g_ctx.mainActivityClass = static_cast<jclass>(env->NewGlobalRef(clz));

    g_ctx.mathsObj = NULL;
    g_ctx.mainActivityObj = NULL;

    env->DeleteLocalRef(clz);

    return  JNI_VERSION_1_6;
}

void callback() {

    JNIEnv* env;

    LOGD("Starting finally ");

    if (g_ctx.javaVM ->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
        LOGD("JNI Error is %d" , JNI_ERR); // JNI version not supported.
    }

    LOGD("Env variable received successfully");

    int status = g_ctx.javaVM->AttachCurrentThread(&env, NULL);

    if(status != JNI_OK) {
        LOGD("Failed to attach the thread");
    } else {

        LOGD("Thread attached successfully");

        jmethodID testMessage = env->GetMethodID(g_ctx.mathsClass, "printMessage",
                                                 "()V");
        // Call the method on the object
        env->CallVoidMethod(g_ctx.mathsObj, testMessage);

        if (env->ExceptionCheck()) {
            env->ExceptionDescribe();
        }

        LOGD("Void Method called Successfully");

        g_ctx.javaVM->DetachCurrentThread();

        LOGD("Thread detached successfully");
    }

    LOGD("This callback is called finally");
}

jfieldID getPtrFieldId(JNIEnv * env, jobject obj)
{
    static jfieldID ptrFieldId = 0;

    if (!ptrFieldId)
    {
        jclass c = env->GetObjectClass(obj);
        ptrFieldId = env->GetFieldID(c, "numberptr", "J");
        env->DeleteLocalRef(c);
    }

    return ptrFieldId;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_example_maths_Maths1_createNumberInstance(JNIEnv *env, jobject thiz, jint a, jint b) {
    // TODO: implement createNumberInstance()

    g_ctx.mathsObj = env->NewGlobalRef(thiz);
    Numbers* num = new Numbers(a, b);
    callback();
    env->SetLongField(thiz, getPtrFieldId(env, thiz), (jlong) num);

}

This is error which I am getting:

2020-06-02 19:25:39.101 15965-15965/com.example.maths A/m.example.math: runtime.cc:2067] Thread[1,tid=15965,Native,Thread*=0xec991800,peer=0x71b391f0,"main"] attempting to detach while still running code
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] Runtime aborting...
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] Dumping all threads without mutator lock held
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] All threads:
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] DALVIK THREADS (17):
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "main" prio=10 tid=1 Runnable
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=0 dsCount=0 flags=0 obj=0x71b391f0 self=0xec991800
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | sysTid=15965 nice=-10 cgrp=default sched=0/0 handle=0xece36dc8
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | state=R schedstat=( 466154407 353144186 350 ) utm=12 stm=34 core=0 HZ=100
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | stack=0xff27a000-0xff27c000 stackSize=8192KB
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | held mutexes= "abort lock" "mutator lock"(shared held)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #00 pc 00493b43  /apex/com.android.runtime/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, int, BacktraceMap*, char const*, art::ArtMethod*, void*, bool)+115)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #01 pc 005b1fd2  /apex/com.android.runtime/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+994)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #02 pc 005ace61  /apex/com.android.runtime/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+65)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #03 pc 005d2cd1  /apex/com.android.runtime/lib/libart.so (art::DumpCheckpoint::Run(art::Thread*)+929)
2020-06-02 19:25:39.497 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #04 pc 005cac06  /apex/com.android.runtime/lib/libart.so (art::ThreadList::RunCheckpoint(art::Closure*, art::Closure*)+486)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #05 pc 005c9e6c  /apex/com.android.runtime/lib/libart.so (art::ThreadList::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool)+2268)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #06 pc 005796f0  /apex/com.android.runtime/lib/libart.so (art::AbortState::DumpAllThreads(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, art::Thread*) const+448)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #07 pc 00564d30  /apex/com.android.runtime/lib/libart.so (art::Runtime::Abort(char const*)+1536)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #08 pc 000249b3  /apex/com.android.runtime/lib/libartbase.so (_ZNSt3__110__function6__funcIPFvPKcENS_9allocatorIS5_EES4_EclEOS3_+35)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #09 pc 0000bac7  /system/lib/libbase.so (android::base::LogMessage::~LogMessage()+727)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #10 pc 005645de  /apex/com.android.runtime/lib/libart.so (art::Runtime::DetachCurrentThread()+414)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #11 pc 003ecc83  /apex/com.android.runtime/lib/libart.so (art::JII::DetachCurrentThread(_JavaVM*)+67)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #12 pc 003e3445  /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::CheckJII::DetachCurrentThread(_JavaVM*)+117)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #13 pc 00009d6a  /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/lib/x86/libnative-lib.so (_JavaVM::DetachCurrentThread()+42)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #14 pc 00009a8a  /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/lib/x86/libnative-lib.so (callback()+554)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #15 pc 0000a24c  /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/lib/x86/libnative-lib.so (Java_com_example_maths_Maths1_createNumberInstance+172)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #16 pc 00144f67  /apex/com.android.runtime/lib/libart.so (art_quick_generic_jni_trampoline+71)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #17 pc 0013e7d2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub+338)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #18 pc 00149a69  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+281)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #19 pc 00332502  /apex/com.android.runtime/lib/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+386)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #20 pc 0032c19c  /apex/com.android.runtime/lib/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+988)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #21 pc 006818dd  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+989)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #22 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #23 pc 0011dc02  [anon:dalvik-classes.dex extracted in memory from /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/base.apk] (com.example.maths.Maths1.<init>+26)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #24 pc 0068461c  /apex/com.android.runtime/lib/libart.so (MterpInvokeDirect+1324)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #25 pc 00138921  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_direct+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #26 pc 0011db02  [anon:dalvik-classes.dex extracted in memory from /data/app/com.example.maths-alZFaEzd-BAd84VC19Fvrg==/base.apk] (com.example.maths.MainActivity.onCreate+26)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #27 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #28 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #29 pc 0019175e  /system/framework/framework.jar (android.app.Activity.performCreate+30)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #30 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #31 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #32 pc 00191726  /system/framework/framework.jar (android.app.Activity.performCreate+2)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #33 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #34 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #35 pc 001eefda  /system/framework/framework.jar (android.app.Instrumentation.callActivityOnCreate+6)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #36 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #37 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #38 pc 00180bb8  /system/framework/framework.jar (android.app.ActivityThread.performLaunchActivity+752)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #39 pc 0068461c  /apex/com.android.runtime/lib/libart.so (MterpInvokeDirect+1324)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #40 pc 00138921  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_direct+33)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #41 pc 00180836  /system/framework/framework.jar (android.app.ActivityThread.handleLaunchActivity+94)
2020-06-02 19:25:39.498 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #42 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #43 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #44 pc 0025e28e  /system/framework/framework.jar (android.app.servertransaction.LaunchActivityItem.execute+126)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #45 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #46 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #47 pc 002607da  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.executeCallbacks+154)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #48 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #49 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #50 pc 00260716  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.execute+146)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #51 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #52 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #53 pc 0017fb6e  /system/framework/framework.jar (android.app.ActivityThread$H.handleMessage+78)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #54 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #55 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #56 pc 002f5846  /system/framework/framework.jar (android.os.Handler.dispatchMessage+38)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #57 pc 00681b4c  /apex/com.android.runtime/lib/libart.so (MterpInvokeVirtual+1612)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #58 pc 00138821  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_virtual+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #59 pc 00319ee6  /system/framework/framework.jar (android.os.Looper.loop+466)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #60 pc 00684fdc  /apex/com.android.runtime/lib/libart.so (MterpInvokeStatic+1260)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #61 pc 001389a1  /apex/com.android.runtime/lib/libart.so (mterp_op_invoke_static+33)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #62 pc 00189466  /system/framework/framework.jar (android.app.ActivityThread.main+194)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #63 pc 002f8e0a  /apex/com.android.runtime/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEbb.llvm.1175793267244191248+298)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #64 pc 002ffcc5  /apex/com.android.runtime/lib/libart.so (art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*)+181)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #65 pc 0066fc49  /apex/com.android.runtime/lib/libart.so (artQuickToInterpreterBridge+1209)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #66 pc 0014503d  /apex/com.android.runtime/lib/libart.so (art_quick_to_interpreter_bridge+77)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #67 pc 0013e9a2  /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+418)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #68 pc 00149a7a  /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+298)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #69 pc 0055a563  /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+99)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #70 pc 0055c37f  /apex/com.android.runtime/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned int)+1327)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #71 pc 004c91a3  /apex/com.android.runtime/lib/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+83)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.example.maths.Maths1.createNumberInstance(Native method)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.example.maths.Maths1.<init>(Maths1.java:16)
2020-06-02 19:25:39.499 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.example.maths.MainActivity.onCreate(MainActivity.java:21)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "Runtime worker thread 0" prio=10 tid=2 Native (still starting up)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=1 dsCount=0 flags=1 obj=0x0 self=0xd9500000
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | sysTid=15991 nice=0 cgrp=default sched=0/0 handle=0xec77fd90
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | state=S schedstat=( 1604515 798906 8 ) utm=0 stm=0 core=1 HZ=100
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | stack=0xec771000-0xec773000 stackSize=63KB
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | held mutexes=
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   kernel: (couldn't read /proc/self/task/15991/stack)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #00 pc 00000b77  [vdso] (__kernel_vsyscall+7)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #01 pc 00092328  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #02 pc 00150802  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+114)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #03 pc 00150783  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::Wait(art::Thread*)+35)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #04 pc 005d4b15  /apex/com.android.runtime/lib/libart.so (art::ThreadPool::GetTask(art::Thread*)+261)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #05 pc 005d3c43  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Run()+83)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #06 pc 005d370f  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Callback(void*)+239)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #07 pc 0011a8e5  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #08 pc 000af6a7  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   (no managed stack frames)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "Jit thread pool worker thread 0" prio=10 tid=3 Native
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=1 dsCount=0 flags=1 obj=0x159c0030 self=0xec98ee00
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | sysTid=15990 nice=0 cgrp=default sched=0/0 handle=0xd9404d90
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | state=S schedstat=( 4160010 1789692 15 ) utm=0 stm=0 core=1 HZ=100
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | stack=0xd9306000-0xd9308000 stackSize=1023KB
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | held mutexes=
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   kernel: (couldn't read /proc/self/task/15990/stack)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #00 pc 00000b77  [vdso] (__kernel_vsyscall+7)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #01 pc 00092328  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #02 pc 00150802  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+114)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #03 pc 00150783  /apex/com.android.runtime/lib/libart.so (art::ConditionVariable::Wait(art::Thread*)+35)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #04 pc 005d4b15  /apex/com.android.runtime/lib/libart.so (art::ThreadPool::GetTask(art::Thread*)+261)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #05 pc 005d3c75  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Run()+133)
2020-06-02 19:25:39.500 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #06 pc 005d370f  /apex/com.android.runtime/lib/libart.so (art::ThreadPoolWorker::Callback(void*)+239)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #07 pc 0011a8e5  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   native: #08 pc 000af6a7  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   (no managed stack frames)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630] "Runtime worker thread 1" prio=10 tid=4 Native (still starting up)
2020-06-02 19:25:39.501 15965-15965/com.example.maths A/m.example.math: runtime.cc:630]   | group="" sCount=1 dsCount=0 flags=1 obj=0x0 self=0xd9508c00


来源: stackexchange

问:
Is there a 2d physics engine that can model fluids and gases?
At this point the platform and programming language don't matter I would just like to know if something out there exists for this. Any help is appreciated.</p>

答:
Here is the most useful thing I was able to find - a box2d add-on prototype written in java:
http://www.jbox2d.org/liquid/

A good discussion about the issue:
http://box2d.org/forum/viewtopic.php?f=3&t=574&hilit=liquid&start=20

ContentLicense: CC BY-SA 3.0


问:
C Programming what happens exactly with this recursive function
i have this function that when i start it prints only even numbers of the entered parameter can anyone explain to me what exactly happens in this function and how it ends up getting the even numbers

```<code>#include <stdio.h>

int what(int x){

    if (x == 0)
        return 0;
    if (x % 2 == 0)
        return what(x / 10) * 10 + x % 10;
    return what(x / 10);
}

int main(){
    printf("%d\n",what(145825));
    return 0;
}
</code>```

output

```<code>482
</code>```

答:
Here's what happens:

The what() function starts with the rightmost digit (= the whole number modulo 10) and then recurses into the rest of the digits by throwing away the rightmost digit (integer division by 10 throws away the right decimal digit).

If the right digit is even it is appended to the result of the recursion by multiplying it by 10 (making space for the extra digit on the right) and adding this digit (= the whole number modulo 10).

If the right digit is odd nothing is added to the result of the recursion.

Recursion stops when there are no more digits.

A good way to figure out to make recursion is to make a table that keeps track of what happens during each step, but of course a debugger is always the best way to really check what happens.

The following table is what happens each time what() is called:

```<code>     x  recursive x  result    even?  returns
------  -----------  ------  -------  -------
145825        14582     482        -      482
       ______/             \_____________
      /                                  \
 14582         1458      48  48*10+2=     482
  1458          145       4   4*10+8=      48
   145           14       4        -        4
    14            1       0   0*10+4=       4
     1            0       0        -        0
     0            -       -        -        0
</code>```

ContentLicense: CC BY-SA 4.0

Body:
i have this function that when i start it prints only even numbers of the entered parameter can anyone explain to me what exactly happens in this function and how it ends up getting the even numbers

#include <stdio.h>

int what(int x){

    if (x == 0)
        return 0;
    if (x % 2 == 0)
        return what(x / 10) * 10 + x % 10;
    return what(x / 10);
}

int main(){
    printf("%d\n",what(145825));
    return 0;
}

output

482

Body:
Here's what happens:

The what() function starts with the rightmost digit (= the whole number modulo 10) and then recurses into the rest of the digits by throwing away the rightmost digit (integer division by 10 throws away the right decimal digit).

If the right digit is even it is appended to the result of the recursion by multiplying it by 10 (making space for the extra digit on the right) and adding this digit (= the whole number modulo 10).

If the right digit is odd nothing is added to the result of the recursion.

Recursion stops when there are no more digits.

A good way to figure out to make recursion is to make a table that keeps track of what happens during each step, but of course a debugger is always the best way to really check what happens.

The following table is what happens each time what() is called:

     x  recursive x  result    even?  returns
------  -----------  ------  -------  -------
145825        14582     482        -      482
       ______/             \_____________
      /                                  \
 14582         1458      48  48*10+2=     482
  1458          145       4   4*10+8=      48
   145           14       4        -        4
    14            1       0   0*10+4=       4
     1            0       0        -        0
     0            -       -        -        0


问:
Creating one grandparent, parent, and child process using fork()
I am trying to fork processes to create exactly one grandparent, parent, and child respectively and display each pid to the standard output. How can I accomplish this? Here is my current code and output:

```<code>#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
int pid, status, status2;
pid = fork();
switch (pid)
{
    case -1: // An error has occured during the fork process.
        printf("Fork error.");
        break;
    case 0:
        pid = fork();
        switch (pid)
        {
            case -1:
                printf("Fork error.");
                break;
            case 0:
                printf("I am the child process C and my pid is %d\n", getpid());
                break;
            default:
                wait(&status);
                printf("I am the parent process P and my pid is %d\n", getpid());
                break;
        }
    default:
        wait(&status2);
        printf("I am the Grandparent process G and my pid is %d\n", getpid());
        break;
    }
}
</code>```

And my output:

```<code>I am the child process C and my pid is 8208
I am the Grandparent process G and my pid is 8208
I am the parent process P and my pid is 8207
I am the Grandparent process G and my pid is 8207
I am the Grandparent process G and my pid is 8206
</code>```

答:
fork() doesn't return 1 in the parent, it returns the pid of the child.

You probably want to change your case 1s to default.

Also, in your outer switch, the case 0 falls through into case 1.  You probably want a break; following the inner switch, between lines 28 and 29.

Body:
I am trying to fork processes to create exactly one grandparent, parent, and child respectively and display each pid to the standard output. How can I accomplish this? Here is my current code and output:

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
int pid, status, status2;
pid = fork();
switch (pid)
{
    case -1: // An error has occured during the fork process.
        printf("Fork error.");
        break;
    case 0:
        pid = fork();
        switch (pid)
        {
            case -1:
                printf("Fork error.");
                break;
            case 0:
                printf("I am the child process C and my pid is %d\n", getpid());
                break;
            default:
                wait(&status);
                printf("I am the parent process P and my pid is %d\n", getpid());
                break;
        }
    default:
        wait(&status2);
        printf("I am the Grandparent process G and my pid is %d\n", getpid());
        break;
    }
}

And my output:

I am the child process C and my pid is 8208
I am the Grandparent process G and my pid is 8208
I am the parent process P and my pid is 8207
I am the Grandparent process G and my pid is 8207
I am the Grandparent process G and my pid is 8206


问:
How to configure identity server 4 to include JTI claim in generated token?
Is there a way to configure Identity Server 4 so that it will automatically include the JTI (unique identifier) claim in the generated token?</p>

答: The documentation now says IncludeJwtId defaults to true. Identity Server Client Documentation


问:
Hyperlinks are staying inactive after setting isEnabled=true to parent control
I've got a TabItem contanining a listbox, which has an obeservable collection of my feeds class as its item source. When I refresh/load the feeds into the collection I want to disable the main window so that the user can't go clicking other things while this process is running. So I set tbCtrl.isEnabled=false; to my tab control on the form. Then assign an event handler to the a custom finish event which is triggered after all the feeds are loaded.

This all works fine, however the hyperlinks for the results which are currently displayed on the tab control never get re-enabled (Nor do the next few which are out of view due to the list box size). All the other results further down are fine, as are the results on the other tab.

I've tried calling InvalidateVisual on the tab control after everything is finished, to see if that makes a difference but that doesn't seem to cause any change.

I could understand it if it was all Hyperlinks doing it, or just the ones currently displayed, but I don't understand why ones which are out of scroll are not working either.

答:
I hit the same issue.

What I did is to bind HyperLink's IsEnabled to the parent, and put that in an App global resource.

```<code><Style TargetType="{x:Type Hyperlink}">
    <Setter Property="IsEnabled" Value="{Binding IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FrameworkElement}}}" />
</Style>
</code>```

Body:
I hit the same issue.

What I did is to bind HyperLink's IsEnabled to the parent, and put that in an App global resource.

<Style TargetType="{x:Type Hyperlink}">
    <Setter Property="IsEnabled" Value="{Binding IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FrameworkElement}}}" />
</Style>


问:
Lex tutorial not using specified lambda function for fulfillment
I'm trying the lex tutorial here and when I get to the point of switching fulfillment to a webhook, it doesn't seem like it's invoking the webhook, and it's completing as if it was not configured to use it.

I have selected the Lambda function as fulfillment for the intent and hit build a a dozen times. Not sure what else I'm supposed to do.

I'm coming from the google side of things so while I think I have a general understanding of how things should work, i have little experience in the amazon stack and its possible that my preconceptions are throwing me off somehow.

答:
There are two separate Lambda "code hook" (webhook) options.

The first is "Lambda initialization and validation" near the middle.

- This sets the Lambda function up as the one that Lex will pass data to every turn of the conversation.

The second is "Fulfillment" towards the bottom.

- This sets the Lambda function up as the one that Lex will pass data to only when Lex is ready to fulfill the intent and close it.

It is common practice to set them both to the same Lambda Function.


问:
Concat column name in SQL
Is there a way to concat a column name as t26.crea+ted_at?

```<code>SELECT t0.id, t0.user, t26.`crea`+`ted_at` FROM users t0
RIGHT OUTER JOIN user_logs t26 ON (t0.id = t26.aid)
WHERE ((t26.`crea`+`ted_at` >= '2018-01-01 00:00:00') AND (t26.`crea`+`ted_at` <= '2019-01-31 23:59:59'));
</code>```

I simply need to fetch data from a certain date but a system is filtering the created_at column because it contains the keyword create

答:
Please use below query,

```<code>SELECT t0.id, t0.user, concat(t26.crea,ted_at) FROM users t0
RIGHT OUTER JOIN user_logs t26 ON (t0.id = t26.aid)
WHERE ((concat(t26.crea,ted_at) >= '2018-01-01 00:00:00') AND (concat(t26.crea,ted_at) <=
'2019-01-31 23:59:59'));
</code>```

You can also use between clause,

```<code>SELECT t0.id, t0.user, concat(t26.crea,ted_at) FROM users t0
RIGHT OUTER JOIN user_logs t26 ON (t0.id = t26.aid)
WHERE concat(t26.crea,ted_at) between '2018-01-01 00:00:00' AND '2019-01-31
23:59:59';
</code>```

Title: Concat column name in SQL

Body:
Is there a way to concat a column name as t26.crea+ted_at?

SELECT t0.id, t0.user, t26.`crea`+`ted_at` FROM users t0
RIGHT OUTER JOIN user_logs t26 ON (t0.id = t26.aid)
WHERE ((t26.`crea`+`ted_at` >= '2018-01-01 00:00:00') AND (t26.`crea`+`ted_at` <= '2019-01-31 23:59:59'));

I simply need to fetch data from a certain date but a system is filtering the created_at column because it contains the keyword create

Body:
Please use below query,

SELECT t0.id, t0.user, concat(t26.crea,ted_at) FROM users t0
RIGHT OUTER JOIN user_logs t26 ON (t0.id = t26.aid)
WHERE ((concat(t26.crea,ted_at) >= '2018-01-01 00:00:00') AND (concat(t26.crea,ted_at) <=
'2019-01-31 23:59:59'));

You can also use between clause,

SELECT t0.id, t0.user, concat(t26.crea,ted_at) FROM users t0
RIGHT OUTER JOIN user_logs t26 ON (t0.id = t26.aid)
WHERE concat(t26.crea,ted_at) between '2018-01-01 00:00:00' AND '2019-01-31
23:59:59';


问:
Does IBM Visual Recognition Support other Data labelling method aside from Bounding Boxes
I'm trying to build a weed detection model  using IBM Visual Recognition service. I have successfully annotated my images with bounding box but the when i try to evaluate my model on a new test image, the model misclassified the new image. I want to know if IBM WATSON support other labelling technique aside from Bounding Box. technique like polygon annotation, semantic, line e-t-c

答: No, it only supports bounding boxes for object detection.</p>


问:
Are there any performance test results for usage of likely/unlikely hints?
gcc features likely/unlikely hints that help the compiler to generate machine code with better branch prediction.

Is there any data on how proper usage or failure to use those hints affects performance of real code on some real systems?

答:
Likely/Unlikely hints work by preloading the ICache with the branch code that is perceived as being generally correct by the programmer.  Branch predictors are, by nature of relying upon limited historical data, effective in loops (or small codebases) only, and loops are not always the issue, with regards to branching performance -- for example, in a real-time simulation, or game, where large amounts of sim/game logic need to be processed for large numbers of objects, at a very high rate.  Branch predictors cannot operate effectively in this context, and this is a serious performance concern for sim developers.  This logic can consist of literally thousands of different, non-repeating conditionals each frame, completely disabling the ability of a branch predictor to operate effectively.

In answer to the original question, compilers tend to assume a conditional will be false, when generating the code to preload the Icache.  You should check the assembly output in your code to verify that, and then you might be able to author a macro for conditionals you want to preload in a performant way, if you don't want to structure your code to fit a particular processor architecture.

Some studies have estimated that modern game engines, on modern processors, spend 60-80% of their time on cache misses, and that branch mis-predictions are approximately 15% of those misses.  In order to accommodate a modern game engine, a branch predictor would need historical data for the entire game logic frame -- probably involving several MB of data for each pipeline.


问:
Determine bounds of shape / graphics drawn into a Canvas
I have a simple HTML5 Canvas example that lets the user draw paths onto a canvas. Is there any way to determine the rectangular bounds of the path / shape that was drawn? (i.e., what is the width, height of the rectangular region surrounding the path).

I realize I could do the math while the shape is being drawn to figure out the bounds, but I wanted to see if there was an easier / built in way.

答:
Inspired by @Phrogz's answer, the answer from Calculate bounding box of arbitrary pixel-based drawing, and his two slightly different demos http://phrogz.net/tmp/canvas_bounding_box.html  and http://phrogz.net/tmp/canvas_bounding_box2.html, here is a version not using the alpha channel (it did not work in my case) but just using a comparison to white color.</p>

```<code>function contextBoundingBox(ctx){
    var w=ctx.canvas.width,h=ctx.canvas.height;
    var data = ctx.getImageData(0,0,w,h).data;
    var x,y,minX,minY,maxY,maxY;
    o1: for (y=h;y--;)        for (x=w;x--;)           if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { maxY=y; break o1 }
    o2: for (x=w;x--;)        for (y=maxY+1;y--;)      if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { maxX=x; break o2 }
    o3: for (x=0;x<=maxX;++x) for (y=maxY+1;y--;)      if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { minX=x; break o3 }
    o4: for (y=0;y<=maxY;++y) for (x=minX;x<=maxX;++x) if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { minY=y; break o4 }
    return {x:minX,y:minY,maxX:maxX,maxY:maxY,w:maxX-minX,h:maxY-minY};
}
</code>```

Body:
Inspired by @Phrogz's answer, the answer from Calculate bounding box of arbitrary pixel-based drawing, and his two slightly different demos http://phrogz.net/tmp/canvas_bounding_box.html  and http://phrogz.net/tmp/canvas_bounding_box2.html, here is a version not using the alpha channel (it did not work in my case) but just using a comparison to white color.

function contextBoundingBox(ctx){
    var w=ctx.canvas.width,h=ctx.canvas.height;
    var data = ctx.getImageData(0,0,w,h).data;
    var x,y,minX,minY,maxY,maxY;
    o1: for (y=h;y--;)        for (x=w;x--;)           if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { maxY=y; break o1 }
    o2: for (x=w;x--;)        for (y=maxY+1;y--;)      if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { maxX=x; break o2 }
    o3: for (x=0;x<=maxX;++x) for (y=maxY+1;y--;)      if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { minX=x; break o3 }
    o4: for (y=0;y<=maxY;++y) for (x=minX;x<=maxX;++x) if ((data[(w*y+x)*4] != 255) && (data[(w*y+x)*4+1] != 255) && (data[(w*y+x)*4+2] != 255)) { minY=y; break o4 }
    return {x:minX,y:minY,maxX:maxX,maxY:maxY,w:maxX-minX,h:maxY-minY};
}


问:
How to convert text from MySQL database to an image using PHP and GD Library?
I have been up and down the Internet for some simple solution and I am simply not finding it. I even opened questions on Stackoverflow with sample code and I've been told that everything is wrong in the code. Then, I don't know what I am doing and my questions get closed IMMEDIATELY. It doesn't make any sense.

All I want to be able to do is Query MySQL database for a text string and then convert it into an image to display on the web browser using PHP and GD Library.

Query Database

Retrieve a TEXT or a STRING (ALPHANUMERIC like any words in English Language) from a MySQL database.

Create an Image using that text for displaying on the browser.

Very similar to what I found on another question, but their answer doesn't work even though it was chosen as a working answer. GD Library image generation does not work with mySQL query   My issue is that I can't Query my database for text and create an image of that text all at once on the same page. Very simple example would be helpful.

Please, help.

答:
If you are looking to change Base64 string of image, this may be the answer

```<code>$entry = base64_decode($stringFromdDatabase);
$image_data = imagecreatefromstring($entry);
$fileName = "sample.jpg";

$dir = [PATH TO WHERE YOU NEED TO STORE IMAGE] . $fileName;
imagejpeg($image_data, $dir);
imagedestroy($image_data);
</code>```

OR CHECK this answer THIS FOR Words to Image
    GD Library image generation does not work with mySQL query

Body:
If you are looking to change Base64 string of image, this may be the answer

$entry = base64_decode($stringFromdDatabase);
$image_data = imagecreatefromstring($entry);
$fileName = "sample.jpg";

$dir = [PATH TO WHERE YOU NEED TO STORE IMAGE] . $fileName;
imagejpeg($image_data, $dir);
imagedestroy($image_data);

OR CHECK this answer THIS FOR Words to Image
    GD Library image generation does not work with mySQL query


问:
Validation in QSpinBox
I have QSpinBox which should take only odd numbers, so I've set initial value to 3 and step to 2.

```<code>QSpinBox* spinBox = new QSpinBox;
spinBox->setValue(3);
spinBox->setSingleStep(2);
</code>```

When I'm using spin box arrows to modify value everything is ok. But when I input value from keyboard it can take not odd numbers to.

So is it possible to set validation which fulfills my requirements without inheriting QSpinBox and redefining its validate method?

My current solution is checking in slot if the value is odd:

```<code>void MyWidget::slotSetSpinBoxValue(int value)
{
    if(value%2 != 0)
    {
         //call function which takes only odd values
    }
    else
    {
        //here I want to show some kind off message that value can only be odd
        //call function with --value parameter
    }
}
</code>```

Second question is how to show some tip for QSpinBox? I would like to show tip like tool tip is shown with message that QSpinBox value should be odd. I've found statusTip property in QWidget but cant find example how to use it.

答:
In python I solved this as follows using the editingFinished property of the spinbox. This only fires a signal when you hit enter or move the focus away from the box. In python I had to pass the function references or the value passed is not the updated one but the one at initialization.:

```<code>class SpinboxExample:
    def __init__(self)
        spinbox = QSpinBox()
        spinbox.editingFinished.connect(
            lambda value=spinbox.value, set_spinbox_val=spinbox.setValue:
            self.value_changed_spinbox(value,set_spinbox_val, set_slider_val)
            )
</code>```

I then had a callback function which checked whether number was odd and if not altered the value in the spinbox to make it odd.

```<code>    def value_changed_spinbox(self, get_value,set_spinbox_value):
        value=get_value()
        if value % 2 == 0:
            value += 1
            set_spinbox_value(value)
</code>```

Hope that helps.

Title: Validation in QSpinBox

Body:
I have QSpinBox which should take only odd numbers, so I've set initial value to 3 and step to 2.

QSpinBox* spinBox = new QSpinBox;
spinBox->setValue(3);
spinBox->setSingleStep(2);

When I'm using spin box arrows to modify value everything is ok. But when I input value from keyboard it can take not odd numbers to.

So is it possible to set validation which fulfills my requirements without inheriting QSpinBox and redefining its validate method?

My current solution is checking in slot if the value is odd:

void MyWidget::slotSetSpinBoxValue(int value)
{
    if(value%2 != 0)
    {
         //call function which takes only odd values
    }
    else
    {
        //here I want to show some kind off message that value can only be odd
        //call function with --value parameter
    }
}

Second question is how to show some tip for QSpinBox? I would like to show tip like tool tip is shown with message that QSpinBox value should be odd. I've found statusTip property in QWidget but cant find example how to use it.

Body:
In python I solved this as follows using the editingFinished property of the spinbox. This only fires a signal when you hit enter or move the focus away from the box. In python I had to pass the function references or the value passed is not the updated one but the one at initialization.:

class SpinboxExample:
    def __init__(self)
        spinbox = QSpinBox()
        spinbox.editingFinished.connect(
            lambda value=spinbox.value, set_spinbox_val=spinbox.setValue:
            self.value_changed_spinbox(value,set_spinbox_val, set_slider_val)
            )

I then had a callback function which checked whether number was odd and if not altered the value in the spinbox to make it odd.

    def value_changed_spinbox(self, get_value,set_spinbox_value):
        value=get_value()
        if value % 2 == 0:
            value += 1
            set_spinbox_value(value)

Hope that helps.


问:
Need assistance with if statement in Python code for SQL
If I want to filter my table using an if statement how would I go about doing this.

I have an example of what I am wanting to do but not sure how to achieve this.

I want to pull a few values based off of the fact that a customer order is active/inactive.

With my sql column being a bit value type I want to only show "orders" based off of active (column value of 0) orders.

Below is my line of code to pull part numbers, customer number, order numbers:

for row in cur:
    custOrders = CST.OrderLog(row[22], row[23], row[39])
    listofCustOrders.append(custOrders)
return listofcustOrders
```

row22 is my part number
row23 is my cust number
row39 is my cust order number

I need to sort my customer order number based off the active/inactive column (row[2]) which consists of just 0,1,NULL values.

Any ideas, I have not worked with if statements regarding a SQL connection before.

Thanks

答:
I think the best solution would be to approach the ordering in the sql query.

If just a order by 'columnname' isn't what you are looking for, you could use a case statement on the query to order it.

See: CASE WHEN statement for ORDER BY clause

Body:
If I want to filter my table using an if statement how would I go about doing this.

I have an example of what I am wanting to do but not sure how to achieve this.

I want to pull a few values based off of the fact that a customer order is active/inactive.

With my sql column being a bit value type I want to only show "orders" based off of active (column value of 0) orders.

Below is my line of code to pull part numbers, customer number, order numbers:

for row in cur:
    custOrders = CST.OrderLog(row[22], row[23], row[39])
    listofCustOrders.append(custOrders)
return listofcustOrders

row22 is my part number
row23 is my cust number
row39 is my cust order number

I need to sort my customer order number based off the active/inactive column (row[2]) which consists of just 0,1,NULL values.

Any ideas, I have not worked with if statements regarding a SQL connection before.

Thanks


问:
CSS hamburger menu cuts in half when closing
I've successfully coded a CSS/JS hamburger menu which has a transforming icon when clicked. However, I've just discovered a bug where, when the hamburger 'close' button is clicked, the nav menu cuts behind the header making it look messy.

Currently, the menu opens correctly when the hamburger is clicked - at 100vh - but when it closes, it appears that it cuts behind the header, so it looks like it's at about 80vh. When it's closing, I'm wanting it to remain at 100vh.

Apologies in advance for the lengthy code.

Here's my code:

// Variables

let line1 = document.getElementById("hamburger-line-1");
let line2 = document.getElementById("hamburger-line-2");
let hamburger = document.getElementById("hamburger");
let navList = document.getElementById("hamburger-nav-list");

// Function

function hamburgerActive() {
  line1.classList.toggle("active");
  line2.classList.toggle("active");
  navList.classList.toggle("active");
}

// Event Listener

hamburger.addEventListener("click", hamburgerActive);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.universal-header-section {
  height: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-container {
  height: 90%;
  width: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px auto;
}

.universal-header-hamburger {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#hamburger {
  height: 20px;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  cursor: pointer;
  z-index: 99;
}

.hamburger-span {
  height: 5px;
  width: 30px;
  background-color: #342b38;
  transition: all .2s ease-in-out;
  cursor: pointer;
}

#hamburger-line-1.active {
  transform: translateY(7.5px) rotate(-45deg);
}

#hamburger-line-2.active {
  transform: translateY(-7.5px) rotate(45deg)
}

.universal-header-logo {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-basket {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

#hamburger-nav-list {
  height: 100vh;
  width: 0;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-direction: column;
  background-color: yellow;
  transition: all 0.5s ease-in-out;
}

#hamburger-nav-list.active {
  height: 100vh;
  width: 30%;
  position: fixed;
}</code>```

Logo

```

Thanks in advance.

答:
Think this is easiest edit to make it work?

Changed the position: absolute / flex

Also the order of DOM elements changed around (most important)

Hope it didnt break anyting :)

// Variables

let line1 = document.getElementById("hamburger-line-1");
let line2 = document.getElementById("hamburger-line-2");
let hamburger = document.getElementById("hamburger");
let navList = document.getElementById("hamburger-nav-list");

// Function

function hamburgerActive() {
  line1.classList.toggle("active");
  line2.classList.toggle("active");
  navList.classList.toggle("active");
}

// Event Listener

hamburger.addEventListener("click", hamburgerActive);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.universal-header-section {
  height: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-container {
  height: 90%;
  width: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px auto;
}

.universal-header-hamburger {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#hamburger {
  height: 20px;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  cursor: pointer;
  z-index: 9999;
}

.hamburger-span {
  height: 5px;
  width: 30px;
  background-color: #342b38;
  transition: all .2s ease-in-out;
  cursor: pointer;
}

#hamburger-line-1.active {
  transform: translateY(7.5px) rotate(-45deg);
}

#hamburger-line-2.active {
  transform: translateY(-7.5px) rotate(45deg)
}

.universal-header-logo {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-basket {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

#hamburger-nav-list {
  height: 100vh;
  width: 0;
  top: 0;
  align-items: center;
  justify-content: space-around;
  flex-direction: column;
  background-color: yellow;
  transition: all 0.5s ease-in-out;
  position:absolute;
}

#hamburger-nav-list.active {
  height: 100vh;
  width: 30%;
  position: fixed;
  z-index: ;
  display:flex;
}</code>```

Logo

  ```

Body:
I've successfully coded a CSS/JS hamburger menu which has a transforming icon when clicked. However, I've just discovered a bug where, when the hamburger 'close' button is clicked, the nav menu cuts behind the header making it look messy.

Currently, the menu opens correctly when the hamburger is clicked - at 100vh - but when it closes, it appears that it cuts behind the header, so it looks like it's at about 80vh. When it's closing, I'm wanting it to remain at 100vh.

Apologies in advance for the lengthy code.

Here's my code:

// Variables

let line1 = document.getElementById("hamburger-line-1");
let line2 = document.getElementById("hamburger-line-2");
let hamburger = document.getElementById("hamburger");
let navList = document.getElementById("hamburger-nav-list");

// Function

function hamburgerActive() {
  line1.classList.toggle("active");
  line2.classList.toggle("active");
  navList.classList.toggle("active");
}

// Event Listener

hamburger.addEventListener("click", hamburgerActive);

.universal-header-section {
  height: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-container {
  height: 90%;
  width: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px auto;
}

.universal-header-hamburger {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#hamburger {
  height: 20px;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  cursor: pointer;
  z-index: 99;
}

.hamburger-span {
  height: 5px;
  width: 30px;
  background-color: #342b38;
  transition: all .2s ease-in-out;
  cursor: pointer;
}

#hamburger-line-1.active {
  transform: translateY(7.5px) rotate(-45deg);
}

#hamburger-line-2.active {
  transform: translateY(-7.5px) rotate(45deg)
}

.universal-header-logo {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-basket {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

#hamburger-nav-list {
  height: 100vh;
  width: 0;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-direction: column;
  background-color: yellow;
  transition: all 0.5s ease-in-out;
}

#hamburger-nav-list.active {
  height: 100vh;
  width: 30%;
  position: fixed;
}

Logo

Thanks in advance.

Body:
Think this is easiest edit to make it work?

Changed the position: absolute / flex

Also the order of DOM elements changed around (most important)

Hope it didnt break anyting :)

// Variables

let line1 = document.getElementById("hamburger-line-1");
let line2 = document.getElementById("hamburger-line-2");
let hamburger = document.getElementById("hamburger");
let navList = document.getElementById("hamburger-nav-list");

// Function

function hamburgerActive() {
  line1.classList.toggle("active");
  line2.classList.toggle("active");
  navList.classList.toggle("active");
}

// Event Listener

hamburger.addEventListener("click", hamburgerActive);

.universal-header-section {
  height: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-container {
  height: 90%;
  width: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px auto;
}

.universal-header-hamburger {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#hamburger {
  height: 20px;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  cursor: pointer;
  z-index: 9999;
}

.hamburger-span {
  height: 5px;
  width: 30px;
  background-color: #342b38;
  transition: all .2s ease-in-out;
  cursor: pointer;
}

#hamburger-line-1.active {
  transform: translateY(7.5px) rotate(-45deg);
}

#hamburger-line-2.active {
  transform: translateY(-7.5px) rotate(45deg)
}

.universal-header-logo {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-header-basket {
  height: 100%;
  width: 33.33%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

#hamburger-nav-list {
  height: 100vh;
  width: 0;
  top: 0;
  align-items: center;
  justify-content: space-around;
  flex-direction: column;
  background-color: yellow;
  transition: all 0.5s ease-in-out;
  position:absolute;
}

#hamburger-nav-list.active {
  height: 100vh;
  width: 30%;
  position: fixed;
  z-index: ;
  display:flex;
}

  <div id="hamburger-nav-list">
    <div class="hamburger-container">

    </div>
  </div>
  <header class="universal-header-section">
    <div class="universal-header-container">
      <div class="universal-header-hamburger">
        <div id="hamburger">
          <span id="hamburger-line-1" class="hamburger-span"></span>
          <span id="hamburger-line-2" class="hamburger-span"></span>
        </div>
      </div>
      <div class="universal-header-logo">
        <a href="index">
          <h2>Logo</h2>
        </a>
      </div>
      <div class="universal-header-basket">
        <a href="basket">
          <i class="fas fa-shopping-cart fa-2x"></i>
        </a>

      </div>
    </div>
  </header>