Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

problems with android examples in processing 3

$
0
0

answering a question about playing sound with android mode i have given 2 solutions (one with APWidget lib, the other with android mediaPlayer class); the twos tested with 3 phones and processing 2, they run fine. However the user tells me that it does not work... and i understood (finally!) that he was using Processing 3 android mode. So i downloaded the last version of P3 (it is 3.06 beta , osX) and installed it on OSX, yosemite.

you can see the question && snippet i posted here: forum.processing.org/two/discussion/12819/how-do-i-get-sound-to-play-on-the-phone#latest

When i runned the code i have posted for android mediaPlayer class (because i was quite sure that APWidgets which was not updated since 2011 cannot work with P3) i firstly get an error from the compiler at the very beginning when i code:

AssetFileDescriptor afd = getAssets().openFd("myp3.mp3");

--- which is a line of code i have often used for that in Eclipse.

Compiler says, as the oop tells (see its picture) that getAssets() does not exists. Of course i have all imports ok.

----I thought that it was a problem with context.

So i tried ::

AssetFileDescriptor afd = this.getAssets().openFd("myp3.mp3");

---same error from ...

So i tried to add to imports the android Context class && wrote::

  (Context)  context = context.getApplicationContext();
    AssetFileDescriptor afd = context.getAssets().openFd("myp3.mp3");

--- here it accepts to compile and install the sketch on the phone... Happy! ----But once installed the app crashes and i get another error, NPE::

"Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference"

----which means that context is null

--- So i decided, in order to verify, to add a very simple class extending Application class from android:::

      public class Appverify extends Application  {

        private  Context ctx;

        public  Context getContext() {
            return ctxt;
        }

        public  void setContext(Context mContext) {
            this.ctxt = ctxt;
        }

    --- then i created an instance of Appverify and called this class + println(context) from its return::

--------result was as i was afraid of:: null

------- Here i begin to be really puzzled and decided to verify with the examples for android, compass && accelerometer -------and found exactly the same results

--------in the twos the constructor does not compile with "this"

(compass = new CompassManager(this);

--------if i change this for context (same method, imports and so on) the error disappears, it compiles, but the app crashes immediately on the phone with the same error "Attempt to invoke virtual method on a null object reference"

----- so, what to do???

last phone with which i tested is running lollipop 5.1, if it matters...

thanks in advance

PS another error i have found is that the line number indicated by console (for errors) does not match the left numbers for the coded lines.


Viewing all articles
Browse latest Browse all 941

Trending Articles