0

I work with SVG format, added a library, all the methods recognized, did everything as in the example and then run NullPointerException ??

I can not understand why ...

Here is my onCreate method in Activity

@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);
}

is such a mistake

    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)

the last line here indicates the line 222 is a line in my onCreate method in which code and crashes.

What am I doing wrong?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • 3
    Looks like either your SVG is invalid, or there's a bug in the parsing library... – Jon Skeet Mar 08 '16 at 13:19
  • @IntelliJAmiya it is a [method in the Java standard library](https://docs.oracle.com/javase/8/docs/api/java/lang/Float.html#floatValue--) – dsh Mar 08 '16 at 13:19
  • i don't understand excectly what do you mean? Can you make exsample maybe? – Sirop4ik Mar 08 '16 at 13:31

2 Answers2

0

Just put the "savedInstanceState" in an "if" block and see what it does. You might actually be passing a "null" state somehow (not very 'pro' in android, so sorry for the dumb suggestion)

pegas
  • 111
  • 1
  • 9
-2

in the class(is it an Activity?) view there is no such view. It usually happens because of one of three reasons:

1) you forgot to setContentView

2) you try to get view before you called setContentView

3) you use a wrong layout in setContentView

please check once for third point

Pitty
  • 1,907
  • 5
  • 16
  • 34
  • This doesn't seem to have paid any attention to the actual exception here. The problem occurs in the SVG parser, where it tries to unbox a `Float`. Could you explain how that would be caused by any of the reasons you've listed? – Jon Skeet Mar 08 '16 at 13:20