2 hui21034475 hui21034475 于 2013.06.18 12:44 提问

Android4.0 执行detectLeakedClosableObjects()报错

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()

.detectDiskReads()

.detectDiskWrites()

.detectNetwork() // or .detectAll() for all detectable problems

.penaltyLog()

.build());

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()

.detectLeakedClosableObjects()

.penaltyLog()

.penaltyDeath()

.build());
在activity中加入后 测试应用报错
06-18 12:43:45.674: E/AndroidRuntime(28299): java.lang.NoSuchMethodError: android.os.StrictMode$VmPolicy$Builder.
06-18 12:43:45.674: E/AndroidRuntime(28299):

at com.xxxxx.on_behalf_of.LoadActivity.onCreate(LoadActivity.java:109)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1692)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1747)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.app.ActivityThread.access$1500(ActivityThread.java:155)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.os.Handler.dispatchMessage(Handler.java:130)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.os.Looper.loop(SourceFile:351)
06-18 12:43:45.674: E/AndroidRuntime(28299): at android.app.ActivityThread.main(ActivityThread.java:3814)
06-18 12:43:45.674: E/AndroidRuntime(28299): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 12:43:45.674: E/AndroidRuntime(28299): at java.lang.reflect.Method.invoke(Method.java:538)
06-18 12:43:45.674: E/AndroidRuntime(28299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
06-18 12:43:45.674: E/AndroidRuntime(28299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
06-18 12:43:45.674: E/AndroidRuntime(28299): at dalvik.system.NativeStart.main(Native Method)

1个回答

Jave_
Jave_   2013.06.18 14:44

你需要判断下当前使用app的系统sdk版本
低版本2.3以下的没有这个
http://android.toolib.net/reference/android/os/StrictMode.VmPolicy.Builder.html

hui21034475
hui21034475 我做2.3的验证
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!