Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
3 replies Latest Post - ‏2011-11-11T02:09:45Z by djna
djna
djna
2 Posts
ACCEPTED ANSWER

Pinned topic Classdef not found when running samples in Emulator

‏2011-10-31T16:53:44Z |
I have a problem running the Phonegap samples provided with the preview. Here's an outline of what is working and what is not.

I have Eclipse Helios, running on Windows 7. The Android 4 emulator is running cleanly, if slowly. Patience is required on startup and it's helpful to show the Logcat view to see progress.

In Eclipse I have created a few Android sample projects, such as Lunar Lander, these deploy and run. There are some errors in some projects but these are not the same problems I see in the Phonegap apps. I see this as evidence that the build/launch cycle from Eclipse to the emulator is not broken.

I have loaded sample-dojoshowcase-android and sample-mysurance-android into Eclipse from the samples directory. These build and deploy but fail to start cleanly the error I see is, for example.

10-31 16:28:53.982: E/AndroidRuntime(1200): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ibm.mobile.dojoshowcase/com.ibm.mobile.dojoshowcase.DojoShowcase}: java.lang.ClassNotFoundException: com.ibm.mobile.dojoshowcase.DojoShowcase

The package and class seem to be present in my project, and the reference in AndroidManifest.xml seems to be similar to the non-Phonegap examples that do launch.

Any suggestions?
Updated on 2011-11-11T02:09:45Z at 2011-11-11T02:09:45Z by djna
  • SystemAdmin
    SystemAdmin
    59 Posts
    ACCEPTED ANSWER

    Re: Classdef not found when running samples in Emulator

    ‏2011-11-01T21:19:39Z  in response to djna
    > {quote:title=djna wrote:}
    > I have loaded sample-dojoshowcase-android and sample-mysurance-android into
    > Eclipse from the samples directory. These build and deploy but fail to start
    > cleanly the error I see is, for example.
    > {quote}

    Its worth knowing how you loaded these samples
    - import?
    - import and copy to workspace?
    - Start with a new android app and copy the pieces over?
    - other?
    I'm working through some of the same issues with windows 7, the Android 4 SDK and Eclipse plugin, and Eclipse Indigo. I've haven't found a variation of the Android 4 emulator that I can reliably start and use, but have been able to instantiate Android 2.2 AVDs and run apps on them.

    Let us know how you got where you are, and we'll see if we can duplicate and unwind.

    Message was edited by: jeffonc - remove extraneous example - explanation in next reply
    Updated on 2011-11-01T21:19:39Z at 2011-11-01T21:19:39Z by SystemAdmin
  • MikeRott
    MikeRott
    1 Post
    ACCEPTED ANSWER

    Re: Classdef not found when running samples in Emulator

    ‏2011-11-01T18:49:53Z  in response to djna
    Short answer: fix your project to define 'src' as an Eclipse source folder by right-clicking the project -> Properties -> Java Build Path -> Source (tab) -> Add Folder -> (select 'src') -> OK.

    Technical explanation:

    Eclipse provides several different ways to get existing projects into its workspace; import existing project (with or without copying to workspace), new project (but pointing at directory where project already exists), or through the Android ADT tools via File -> New -> Other... -> Android -> Android Project (with "use existing source" radio selection). The latter is now my preferred way as it invokes Android ADT hooks properly.

    In the first TechPreview, we advocated Eclipse's import existing project because you could import many at the same time. This may result in project problems due to physical 'src' folder not being defined in Eclipse as a "source" folder. Thus the source code that is physically present in your project is not defined as source code in eclipse, never gets into the built apk, and thus is not found when trying to run the application. The fix, in this flow, would be to right-click project -> Properties -> Java Build Path -> Source (tab) -> Add Folder -> (select 'src') -> OK. You may also have to do the same for 'gen'.

    Without the above manual fix, the project will import without error, build without error, and install an APK without error, but will have no compiled code and thus you will get a ClassNotFoundException for the class defined by the AndroidManifest.xml as your application's entry Activity.

    I recommend using the Android tools, so that more user errors can be eliminated. However, this requires that we do not define 'src' and 'gen' as source folders in the sample project's .classpath file. If we leave these definitions in, and the user uses File -> New -> Other -> Android -> Android Project -> use existing source, they will see an error about "Build path contains duplicate entry: 'src' for project 'xxxxx'", because both the .classpath file and the Android classpath container will attempt to define 'src' as an Eclipse source folder in the new project. With the definitions removed, if the user attempts to import the project the Eclipse way, they'll run into the issue you encountered, and would have to manually fix their newly imported project.
  • djna
    djna
    2 Posts
    ACCEPTED ANSWER

    Re: Classdef not found when running samples in Emulator

    ‏2011-11-11T02:09:45Z  in response to djna
    Thanks for the answer, creating the project as described was the key.

    I have written this up, along with a couple of other wrinkles, in my blog

    http://djna.wordpress.com/2011/11/02/ibm-mobile-technology-preview-getting-started/
    Updated on 2011-11-11T02:09:45Z at 2011-11-11T02:09:45Z by djna