Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

java's class.getResource() is null?

Discussion in 'Android' started by komodoman, Sep 27, 2012.

  1. komodoman

    komodoman

    Joined:
    Sep 27, 2012
    Posts:
    2
    Hi guys,

    We are loading jars into unity (android). We are encountering an error with one of our Jars:

    Log.d("ad_e1", getClass().toString());
    Log.d("ad_e2", getClass().getClassLoader().toString());
    Log.d("ad_e3", getClass().getClassLoader().getResource(getClass().getSimpleName() + ".class").toString());


    the last line keeps returning an error

    09-27 14:59:20.757: E/Ad(3024): java.lang.NullPointerException

    I've searched in google and unity forums, found nothing. :( anyone who can help? please?

    Edit:

    I also did the following:

    Log.d("ad_e4", getClass().getResource(getClass().getSimpleName() + ".class").toString());

    still fails with the same exception. These works if I build in eclipse though. (Export unity project to eclipse and build there). I don't want to do that however, since they say the procedure is a bit of a hack and I experience losing some unity features (like streaming audio).
     
    Last edited: Sep 27, 2012
  2. komodoman

    komodoman

    Joined:
    Sep 27, 2012
    Posts:
    2
    To anyone interested,

    I downloaded a tool to unpack an apk and it turns out that unity strips out non-code stuff out of jars. So if you have images on a jar and put the jar into unity, the output apk will not have the images inside the jar. So if you have jars with images (like ad jars or the facebook jar) most likely those will not work out of the box and you will have to write a way to read images from inside unity and push them out to your java jar.

    At this point, getResource() or getResourceAsStream() is no longer the issue as there will be no point (for me, at least) to use the said function if the resource to load doesn't even exists.

    Edit:

    We'll just have to export the project to eclipse and if anything breaks, create our own implementation.
     
    Last edited: Sep 27, 2012
  3. jiecuoren

    jiecuoren

    Joined:
    Nov 3, 2014
    Posts:
    2

    That's really good. Is there any way for don't export project?