我使用以下java代码检查用户的主机文件,看看他们是否在我的应用中屏蔽了广告(因此,我可以弹出一个说明我需要广告费的原因的窗口,等):
public boolean IsAdBlocked()
{
BufferedReader in = null;
try
{
in = new BufferedReader(new InputStreamReader(new FileInputStream("/etc/hosts")));
String aLine;
while ((aLine = in.readLine()) != null) if (aLine.contains("admob")) return true;
}
catch (IOException e)
{
}
return false;
}
我用C ++用以下函数调用它:
bool JavaBridge_IsAdBlocked()
{
JNIEnv* threadEnv;
g_theJavaVirtualMachine->GetEnv ((void **) &threadEnv, JNI_VERSION_1_4);
jclass aObject = threadEnv->FindClass(ACTIVITY_NAME);
if(aObject==NULL) {return true;}
jmethodID aFunction = threadEnv->GetMethodID(aObject, "IsAdBlocked", "()Z");
if(aFunction==NULL) {return true;}
jboolean aBool=threadEnv->CallBooleanMethod(g_theGlobalRefToActivityInstance,aFunction);
threadEnv->DeleteLocalRef(aObject);
return (aBool!=0);
}
当应用程序崩溃时,我得到以下堆栈跟踪:
#01 pc 00000000000484b3 /system/lib/libc.so(pthread_kill + 34)
#02 pc 000000000001dd89 /system/lib/libc.so( raise + 10)
#03 pc 0000000000019511 /system/lib/libc.so(__libc_android_abort + 34)
#04 pc 0000000000017150 /system/lib/libc.so(abort + 4)
#05 pc 000000000031ba35 /system/lib/libart.so(_ZN3art7Runtime5AbortEv + 252)
#06 pc 00000000000b4ccb /system/lib/libart.so(_ZN3art10LogMessageD2Ev + 866)
#07 pc 00000000001bc861 /system/lib/libart.so(__ZN3art22IndirectReferenceTable17AbortIfNoCheckJNIEv + 84)
#08 pc 000000000023db6f /system/lib/libart.so(__ZNK3art22IndirectReferenceTable10GetCheckedEPv + 498)
#09 pc 000000000023ad1f /system/lib/libart.so(__ZN3art9JavaVMExt12DecodeGlobalEPv + 10)
#10 pc 0000000000335785 /system/lib/libart.so(__ZNK3art6Thread13DecodeJObjectEP8_jobject + 124)
#11 pc 000000000031789f /system/lib/libart.so(__ZN3art35InvokeVirtualOrInterfaceWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDSt9__va_list + 42)
任何人都可以解释导致什么情况导致" ScopedObjectAccessAlreadyRunnable"螺旋式地完全毁灭?
答案 0 :(得分:0)
虽然批评你的方法的评论是非常合理的,但最可能的原因是你的JNI在一个本地线程上运行,而该线程还没有attached到JVM。
答案 1 :(得分:0)
您永远不会关闭输入流。