我与SVG格式的工作,增加了一个图书馆,所有的方法承认,做了一切作为例子,然后运行NullPointerException
?为什么抛出NullPointerException?
我不明白为什么...
这是我在活动onCreate方法
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
RelativeLayout rlHumanBody = (RelativeLayout) findViewById(R.id.control);
\\But in this line error
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.frontfigure);
Drawable drawable = svg.createPictureDrawable();
rlHumanBody.setBackground(drawable);
}
是这样的错误
FATAL EXCEPTION: main
Process: com.example.android.camera2basic, PID: 4396
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.
android.camera2basic/com.example.android.camera2basic.CameraActivity}:
com.applantation.android.svg.SVGParseException: java.lang.NullPointerException:
Attempt to invoke virtual method 'float java.lang.Float.floatValue()' on a null
object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java :903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: com.applantation.android.svg.SVGParseException: java.lang.
NullPointerException: Attempt to invoke virtual method 'float java.lang.Float.
floatValue()' on a null object reference
at com.applantation.android.svg.SVGParser.parse(SVGParser.java:211)
at com.applantation.android.svg.SVGParser.getSVGFromResource(SVGParser.java:1 10)
at com.example.android.camera2basic.CameraActivity.onCreate(CameraActivity.java:222)
最后一行在这里表示线222在我的onCreate
方法中的一行代码和崩溃。
我在做什么错?
在类(它是一个活动时间)
看起来像是你的SVG无效,或者解析库中有一个错误... –
@Neil Haaaa .I知道 –
@IntelliJAmiya它是[在Java标准库方法](https://docs.oracle.com/javase/8/docs/api/java/lang/Float.html#floatValue- - ) – dsh