Trouble in android mode, using "loadImage()" & "orientation(LANDSCAPE)"?

edited March 13 in Android Mode

Hello I am new to processing. I am having trouble with processing in the android mode, using "PImage" and "loadImage" when I choose "orientation(LANDSCAPE);". My simplyfied Code:


     import java.util.*;  //To use ArrayList
    ArrayList<PImage> bilder_a;

    void setup() {
      fullScreen();  
      orientation(LANDSCAPE);
      background(0);  

      //Load Pictures:
      bilder_a=new ArrayList<PImage>(); 
      int pic_anzahl=9;
      String pic_name;
      for (int i=0; i<=pic_anzahl; i++)
      {
        pic_name="pic_a"+i+".JPG";
        bilder_a.add(loadImage(pic_name));
      }
    }

I use the newest stable Version of processing, 3.3 and the newest and stable Version of SDK for Windwos 10, 64Bit. I already reinstalled the two, to see whether there is a software failure. But it does not solve anything. In my Sketch folder, I have the "data" folder with all the pictures... I am using an Oukitel K10000. My code works fine, when I run it in Java-Mode, but fails in Android-Mode:

-post-build:

debug: FATAL EXCEPTION: Animation Thread Process: processing.test.trouble, PID: 11536 java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.app.Activity.getAssets()' on a null object reference at processing.core.PApplet.createInputRaw(Unknown Source) at processing.core.PApplet.createInput(Unknown Source) at processing.core.PApplet.loadImage(Unknown Source) at processing.test.trouble.trouble.setup(trouble.java:36) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:818) [The application does not crash, when I start it with my smartphone turned to the right landscape mode, but that is obviously not a solution...]

The strange thing is..., the Code works fully-fine even in Android-Mode, when I delete the line "orientation(LANDSCAPE);" or when i delete the line "bilder_a.add(loadImage(pic_name));". I know, the LANDSCAPE and PImage-stuff had been discussed like a thousand times.. but I never found a discussion, that focuses, the combination of LANDSCAPE and PImage, which obviously makes me trouble.

I hope you can help me, thanks a lot by now!

Answers

  • Not sure if this will fix things, but try:

    void settings(){
         fullScreen(); 
    }
    
    void setup() {
      orientation(LANDSCAPE);
    
      .....THE REST OF THE CODE FOLLOWS
    

    Also it would be great to see how you manage your images... aka. what your draw function looks like.

    Kf

  • edited March 14

    @firepille===

    from the error code the error is with your images that are nor found (or loaded). In order to be sure try this part of your code in java mode.

  • edited March 14

    Thanks for the fast answer @kfrajer, but it does not solve my problem, the application breaks a half second later... I don't think the problem is because of the image organization and the image drawing, because it fails even before I attempt to draw anything... so the draw function of the upper code could look like this :

    void draw()
    {
        background(0, 0, 0);
    }
    

    A bigger Version with Image organization would look like this:

    import java.util.*;  //To use ArrayList
    ArrayList<PImage> bilder_a;
    ArrayList<PImage> bilder_b;
    int count;
    void setup() {
      //size(displayWidth,displayHeight,OPENGL); 
      fullScreen();
      orientation(LANDSCAPE);
      background(0);  
    
      //Load Pictures:
      bilder_a=new ArrayList<PImage>(); 
      bilder_b=new ArrayList<PImage>(); 
      int pic_anzahl=9;
      String pic_name;
      for (int i=0; i<=pic_anzahl; i++)
      {
        //pic_name="test.jpg";
        pic_name="pic_a"+i+".JPG";
        bilder_a.add(loadImage(pic_name));
        pic_name="pic_b"+i+".JPG";
        bilder_b.add(loadImage(pic_name));
      }
      count=0;
    }
    void draw()
    {
      background(0, 0, 0);
      if (count<10)
      {
        image(bilder_a.get(count), 0, 0, width, height);
        count++;
      } else
      {
        image(bilder_b.get(count-10), 0, 0, width, height);
        count++;
        if (count==19)
        {
          count=0;
        }
      }
    }
    
  • thanks @akenaton, as i have allready mentioned in my questions, the pictures work fine in java mode! even in android mode they can be loaded and displayed in portait or landscape, but only if I delete the line "orientation(LANDSCAPE);".. the point is, i want to force landscape, because otherwise it looks crappy...

  • edited March 14 Answer ✓

    @firepille===

    sorry, i have not seen the last lines from your post because they were in the error code... So i see better now; first thing is to add landscape in the manifest and not (or not only, you can try): it s easy you only write

    android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation|screenSize"

    in your activity tag

    another hint could be to load your images in draw() with a boolean (kind of (if(!loaded)...{}

    PS: normally, as @kfrajer said you have to put your fullscreen() in settings, not in setup() with p5 3.x

  • ... am I right, simply editing the AndroidManifest XML-Document in the sketchbook with a simple texteditor and than simply save it? or do i have to update something?

  • <?xml version="1.0" encoding="UTF-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
      <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23"/>
      <application android:debuggable="true" android:icon="@drawable/icon" android:label="">
        <activity android:name=".MainActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar">
          <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
          </intent-filter>
        </activity>
      </application>
    </manifest>
    
  • @akenaton thanks a lot.. i have tried this like a thousand times.. and now it simply works... i do have no idea why it used to fail... thank you!

  • Maybe did you have screen rotation disabled in your phone? I am not 100% sure if this could cause a problem or if changes in the code (or in the manifest) will override this user setting in the settings menu. It is great to hear it is working now. If you remove the lines in the manifest, you don't those issues anymore?

    Kf

Sign In or Register to comment.