0

When I launch my app this problem shows. This is my Java code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(layout.activity_main);
    ImageView imageView = new ImageView(this);

    imageView.setBackgroundColor(Color.WHITE);

    SVG svg = SVGParser.getSVGFromResource(getResources(), raw.canel);`


    imageView.setImageDrawable(svg.createPictureDrawable());
   setContentView(imageView);
}
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
Imèd Digà
  • 19
  • 1
  • 1
  • It would be helpful if you could paste the stack trace of this exception. In which line does the error occurs? – ZeusNet Dec 30 '16 at 12:53
  • The exception message is pretty self-explanatory. However I don't see you calling the method `floatValue` in your code, show us where you call it. – Alexandru Severin Dec 30 '16 at 12:54
  • Also, what is your question? – Alexandru Severin Dec 30 '16 at 12:54
  • the line cause the problem is – Imèd Digà Dec 30 '16 at 12:57
  • the line cause the problem is the line cause the problem is SVG svg = SVGParser.getSVGFromResource(getResources(), raw.canel);` – Imèd Digà Dec 30 '16 at 12:59
  • my quest is what sould i do for making my app launch – Imèd Digà Dec 30 '16 at 12:59
  • Could it be that `raw.canel` is a null `Float` reference and `SVGParser.getSVGFromResource()` expects a primitive `float`? I’m guessing a bit here. I don’t think we have enough information to do better. – Ole V.V. Dec 30 '16 at 13:02
  • (or maybe expects some other primitive type, perhaps `double`) – Ole V.V. Dec 30 '16 at 13:03
  • okey , thanks bur raw.canel is not null its SVG file then i see tutorial like this and it work normaly ,so i dont understand what i should do ,thanks for helping – Imèd Digà Dec 30 '16 at 13:05
  • This particular `NullPointerException` may (or may not) come from auto-unboxing a `Float` object. Hence my previous comments. – Ole V.V. Dec 30 '16 at 16:05
  • I suspect it is not the line you list itself that is failing, but something deeper inside the SVG parser. It may be something in your SVG file that your library is not handling properly. It looks like you are using the svg-android library. Have you tried an alternative library, such as AndroidSVG? – Paul LeBeau Dec 31 '16 at 12:27
  • You may want to edit your question to include a full stacktrace and it would probably be easier to help. – Ole V.V. Jan 01 '17 at 20:29

1 Answers1

2

This is the line where the exception is thrown:

SVG svg = SVGParser.getSVGFromResource(getResources(), raw.canel);

There are two possibilities: either SVGParser is null and therefore has no getSVGFromResource, or raw is null and has no canel member.

If your error is that SVGParser is null, then the problem is that you did not import SVGParser. In this case the solution is to import the package which contains SVGParser, since it is a class and it was not imported, therefore the compiler thinks it is a variable and has not been initialized.

If your error is that raw is null, then the solution is to initialize it. In this case you have missed the part where the variable is being initialized. It is quite possible that you initialize it correctly, but after onCreate is being called, therefore the member is not initialized yet when you try to use it.

We need more information about the problem to give you a more specific solution.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175