Posts Tagged ‘ java

Android Adventures, part 2

Go to part 1, part3…

Based on the success of my previous post covering how I got my Android phone (Samsung Captivate) rooted, the “Scripting Language For Android” installed with Python, it was time to get Processing working on it.

Of course, it wouldn’t go easy or smoothly…

A.  Install Processing For Android & Dependencies

Following the ‘Instructions‘ sections on the “Processing For Android” page, I installed:

B.  Try Out Some Code

I started with these two tutorials, trying to walk through them to get the code working:

I immediately ran into problems…

C. Troubleshooting:

First problem:

Couldn’t get the Android emulator to run any of the example code.  The first  error I got  started like this:

Importing rules file: tools\ant\ant_rules_r3.xml
G:\android-sd\tools\ant\ant_rules_r3.xml:336: Error running javac.exe compiler

Websearching, I found someone else with the exact problem here.  On that thread a fix was posted which linked here.  Looking at that suggestion, I ended up doing these actions, which fixed the emulator problem:

  • I added all of these dirs to my PATH system variable (Windows XP):
    • C:\android-sdk-windows;
    • C:\android-sdk-windows\tools;
    • C:\Program Files\Java\jdk1.6.0_21\bin;
  • I added a ‘ANDROID_SDK’ system variable, pointing it to ‘C:\android-sdk-windows’ dir.
  • I had also previously added a ‘SDK_ROOT’ system variable pointing to ‘C:\android-sdk-windows\tools’ dir.

I should point out that maybe not all of those steps needed to be done, but after I did it all, I could finally get my sketches to load on the Android Emulator.

Second Problem:

When I tried to load the sketches on the phone itself via “Presentation Mode” in Processing, I got a new error:

“Device time out”
“Device killed or disconnected”

The computer wasn’t seeing the phone.  In a nutshell:  I had to switch the phone’s USB mode to “Enable USB Debugging”.  By doing that, the computer once again failed to recognize the phone  since  the phone seemed to be in a ‘new usb mode’.  Unplugging it and reconnecting it asked for me to reinstall the USB drivers again, twice in a row.  But once the drivers updated, I was able to get the sketches loaded on the phone.  Success!

D.  Try Out Some Code (Again)

I was then able to go through both the above tutorials getting the code running on both the emulator, and on my phone itself.  The examples are simple, but they look amazing on that screen.

I can’t wait to start writing some real code and getting it up on the phone.  And I still need to figure out how to actually save it on the phone, and run it later… 😉


So, the next day I found out that Processing installs the sketches on the phone when you run them.  I found them sitting in the Applications menu, named after the sketch that made them.  I just hadn’t noticed when I initially loaded them.   Nice!

Go to part 1, part3…

Compare Jython and Java swing authoring

Since I’m teaching myself Java, and recently installed Jython, I thought it would be interesting to compare the two for authoring swing UI’s.  To aid in this development, I got the PyDev plugin for Eclipse installed, allowing for me to use Eclipse as an IDE for Jython and Python, nice.  FYI, I am by no means an expert at swing, or Java.  But the examples do work :)

Both examples display identical “Hello World!” window.

Here’s the Jython:

from javax.swing import *
from java.awt import *

class TextTest(JFrame):
    def __init__(self):
        JFrame.__init__(self, "TextTest")
        self.setSize(256, 128)
        pane = HelloPane()

class HelloPane(JPanel):
    def paintComponent(self, comp):
        f = Font("Arial", Font.PLAIN, 32)
        comp.drawString("Hello World!", 32, 64)

if __name__ == "__main__":
    tt = TextTest()

And here’s the Java:

import javax.swing.*;
import java.awt.*;

public class TextTest extends JFrame {
    public TextTest() {
        setSize(256, 128);
        HelloPane pane = new HelloPane();

    public static void main(String[] arguments) {
        TextTest frame = new TextTest();

class HelloPane extends JPanel {
    public void paintComponent(Graphics comp) {
        Graphics2D comp2D = (Graphics2D)comp;
        Font f = new Font("Arial", Font.PLAIN, 32);
        comp2D.drawString("Hello World!", 32, 64);


jythonAs I delve deeper into my new ‘Learning Java Book‘, I continue to miss Python more and more.  Not that I don’t find Java an impressive language; it’s amazing what us humans can come up with.  But considering I learned Python first, Java (and every other languange I’ve ran into) seem… less desirable in comparison.  I know them’s fightin’ words in some parts, but hey, this is my blog.

I’d known about Jython for some time, but it finally clicked in my head:  Why not try it?  It’s Java, but it acts like Python.  After an easy download and installation, I fired up it’s ‘jython.bat’ file (on WinXP) and there before me was the Python (er… I mean Jython) prompt.  It was an eerie feeling using an interactive  Jython shell to import ‘javax.swing’ and make a simple UI, but it worked flawlessly.  And so much easier than having to jump through all those Java hoops requiring you to make extraneous classes, etc.

From an online tutorial:


Thus creates:


I’m not sure where Jython will take me, but it sure makes me warm up to Java more :)  Next step will be to get it running in Eclipse

Android anyone?

android01While I’ve really been enjoying coding with Pygame and Python… one thing they don’t seem to be able to do is play well with mobile phones.  Specifically things like the iPhone and Android devices.  Everyone I show my BubblePaint Pygame program to has the same comment:  You should put that on the iPhone!  And I’d love to!  But I don’t see Python entering into the iPhone’s future anytime soon, and I have no real want to learn Objective-C or C++ for iPhone dev.  Plus, I really don’t want to have to buy a Mac just to release my iPhone apps :-S

Enter Android.  Can develop for it on the PC (plus!).  Uses Java as its programming language.  And now appears to support Python scripting!  So far so good! (well, other than the fact I signed a 2-year deal with AT&T so my wife could get an iPhone <wink> )

I’m a bit warmer to Java than other languages based on my familiarity with Processing.  But I still really don’t “know Java” (however I have to say that Processing was a gentle introduction).  So I went out this weekend and picked up these books:

Then I:

  • Installed Eclipse IDE, since the Android platform has some Eclipse-specific plugins to aid in it’s development.
  • Installed the Android SDK (thanks to this post)

And finally I:

  • Started reading the Java book.

I’m now on… day 3… of 21.  It’s going pretty fast since Java is not so unlike Python in many regards.  The only thing I find unfortunate is that the more I learn of Java… the more I miss Python.  Python’s dynamic typing is sooooo much more conducive to my brain than Java’s static typing, and the stripped down syntax of Python just makes me feel… cleaner, compared to all the brackets, semi-colons, variable casting and whatnot needed in Java.  Bah!  End rant.

We’ll see where this leads:  I really like the idea of making games on mobile devices, and Android seems like an accessible platform.  I just hope AT&T starts selling the devices soon (the emulator will only get me so far) and learning Java doesn’t  cause me to rant too much….


Just ran into HYPE

HYPE appears to be to ActionScript 3 as Procesing is to Java.  I like seeing these higher-level wrappers of the languages available to the user community:  I was really excited when I first started using Processing, it opened a lot of doors for me creatively.  Looking forward to seeing what the HYPE user-community produces.