问题链接如下所述
[上一个链接] [1]
Android Jelly_Bean 4.2的错误日志
04-15 10:11:48.709 12956-12956/com.example.this_pc.framelayout E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.this_pc.framelayout.ImagePicker.getTempFile(ImagePicker.java:112)
at com.example.this_pc.framelayout.ImagePicker.getImagePicker(ImagePicker.java:48)
at com.example.this_pc.framelayout.MainActivity$1.onClick(MainActivity.java:37)
at android.view.View.performClick(View.java:4432)
at android.view.View$PerformClick.run(View.java:18338)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
[1]: http://stackoverflow.com/questions/36621097/image-is-not-setting/36621144#36621144
Android 6.0的错误日志
04-15 10:18:47.114 3754-3754/com.example.this_pc.framelayout E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.this_pc.framelayout, PID: 3754
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=234, result=-1, data=Intent { dat=content://media/external/images/media/34 }} to activity {com.example.this_pc.framelayout/com.example.this_pc.framelayout.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileDescriptor android.content.res.AssetFileDescriptor.getFileDescriptor()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileDescriptor android.content.res.AssetFileDescriptor.getFileDescriptor()' on a null object reference
at com.example.this_pc.framelayout.ImagePicker.decodeBitmap(ImagePicker.java:130)
at com.example.this_pc.framelayout.ImagePicker.getImageResized(ImagePicker.java:151)
at com.example.this_pc.framelayout.ImagePicker.getImageFromResult(ImagePicker.java:103)
at com.example.this_pc.framelayout.MainActivity.onActivityResult(MainActivity.java:50)
at android.app.Activity.dispatchActivityResult(Activity.java:6428)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-15 10:18:49.745 3754-3754/com.example.this_pc.framelayout I/Process: Sending signal. PID: 3754 SIG: 9
答案 0 :(得分:0)
对API 14和15使用{
"name": "myproject",
"version": "0.0.1",
"scripts": {
"postinstall": "./node_modules/.bin/webdriver-manager update --standalone && ./node_modules/.bin/bower install",
"test": "./node_modules/.bin/protractor test/functional/protractor.conf.js"
},
"dependencies":
{
"async": "^0.9.0",
"hapi": "~8.2.0",
"hapi-seneca": "^1.0.3",
"seneca": "git://github.com/rjrodger/seneca.git",
"seneca-account": "^0.1.8",
"seneca-auth": "git://github.com/rjrodger/seneca-auth.git",
"seneca-card": "^0.1.3",
"seneca-project": "^0.1.4",
"seneca-user": "~0.2.10"
},
"devDependencies": {
"protractor": "~1.7.0",
"bower": "~1.3.12"
}
}
,对API 16 +使用setBackgroundDrawable()
:
所以你必须将Bitmap转换为BitmapDrawable
像
setBackground()
然后只需用下面的函数设置位图
BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap)