Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Android Studio - "hello world"

  • 11-12-2014 10:46pm
    #1
    Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭


    Hi all,

    Can someone point me at a reliable "hello world" bit of code to test out Android Studio? I thought I had a reasonable looking one, but after downloading several gajigabytes of assorted SDKs & stuff, when I push the app to my tablet it blows up. In all my years of hacking bits & pieces of code this is the first time I've managed to make "hello world" do that. It reminds me of this somehow -http://funnyfailpictures.com/2010/05/homer-simpson-corn-flakes-flambee.html. When I hit "build" it builds OK, but when I hit "run" it complains and blows up on screen.

    I even downloaded the code that came with the tutorial I was working with since "there's no way this won't work", but after getting me to download several more gajigabytes of stuff it also failed, even more spectacularly.

    I'm not looking for someone to reverse engineer my failed code or provide full on tutorials on app development, but can someone point me to a "hello world" tutorial which they are reasonably confident that a beginner can download to the device and run?

    Thanks,

    z


Comments

  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    What's making it crash? Do you know how to see the crash in logcat?

    If you're using android studio picking a blank activity when setting up a project builds a working hello world app


  • Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭zagmund


    Thanks for the reply. The tablet just says ""Unfortunately Hello World App has stopped".

    Logcat says
    12-14 16:31:02.634  20027-20027/com.example.zag.helloworldapp I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
    12-14 16:31:02.634  20027-20027/com.example.zag.helloworldapp I/SELinux﹕ Function: selinux_android_load_priority [1], There is no sepolicy version file.
    12-14 16:31:02.634  20027-20027/com.example.zag.helloworldapp I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=GOOGLE_POLICY
    12-14 16:31:02.634  20027-20027/com.example.zag.helloworldapp I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
    12-14 16:31:02.634  20027-20027/com.example.zag.helloworldapp D/dalvikvm﹕ Late-enabling CheckJNI
    12-14 16:31:02.739  20027-20027/com.example.zag.helloworldapp D/AndroidRuntime﹕ Shutting down VM
    12-14 16:31:02.739  20027-20027/com.example.zag.helloworldapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41e04c08)
    12-14 16:31:02.744  20027-20027/com.example.zag.helloworldapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.example.zag.helloworldapp, PID: 20027
        java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zag.helloworldapp/com.example.zag.helloworldapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.zag.helloworldapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.zag.helloworldapp-3.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.zag.helloworldapp-3, /vendor/lib, /system/lib]]
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
                at android.app.ActivityThread.access$900(ActivityThread.java:175)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:146)
                at android.app.ActivityThread.main(ActivityThread.java:5603)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.zag.helloworldapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.zag.helloworldapp-3.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.zag.helloworldapp-3, /vendor/lib, /system/lib]]
                at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
                at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
                at android.app.ActivityThread.access$900(ActivityThread.java:175)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:146)
                at android.app.ActivityThread.main(ActivityThread.java:5603)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                at dalvik.system.NativeStart.main(Native Method)
    

    I can make enough out of that to see that it
    didn't find class "com.example.zag.helloworldapp.MainActivity" on path

    My AndroidManifest.xml looks like this -
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.zag.helloworldapp">
    
        <application android:allowBackup="true"
            android:label="@string/app_name"
            android:icon="@drawable/ic_launcher"
            android:theme="@style/AppTheme">
    
            <activity android:name=".MainActivity" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    
    </manifest>
    

    If I understand the error log correctly it can't find ".MainActivity" anywhere in the path. I'm not sure if this is App Studio telling me this or it's the tablet telling me this. I tried to get over this by specifying
    <activity android:name="com.example.zag.helloworldapp.MainActivity" >
    
    but that didn't help.

    How come it builds correctly (CTRL-F9) without having this path issue, but doesn't run?

    z


  • Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭zagmund


    MainActivity.java looks like this -
    package com.example.zag.helloworldapp;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    
    
    public class MainActivity extends Activity{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    }
    

    z

    p.s. the build process created another 759 files, but I've no idea whether any of them are used (other than the icon & theme stuff referenced in the code)


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    Hard to see any error there, can you try creating a completely new project from scratch in Android studio and running that to see if it works OK?

    Have you tried running the code you have in an emulator?

    Another thing to check is to see what version of Android is your minimum in your build.gradle file and check it against what version the tablet is running.


  • Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭zagmund


    Hmm, weird. I just created a new project called "HelloWorld" and it automagically prepopulated enough stuff to make it run and print "Hello World!". I never, ever put "!" into text strings so this must have been written automatically.

    My entire notes are - "Set minimum SDK to API15 4.0.3, Add blank activity, Activity name -> MainActivity"

    I managed to change the string and push it down to my tablet successfully, so that is huge progress.

    Regards the emulator - it just won't kick off for me. I get this - "C:\Users\zag\AppData\Local\Android\Sdk\tools\emulator.exe -avd Nexus_5_API_21_x86 -netspeed full -netdelay none" showing that the emulator is being called, but then nothing happens. No error message, no flash on screen as something tries to load. Nada.

    z


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    Yes, Android Studio creates the Hello World application straight off the bat.

    For Emulators try Genymotion, they are far better than the built in one.


  • Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭The_B_Man


    FYI, if you have an Intel CPU in your machine, install this and the emulators will run a lot smoother (assuming u pick the Intel images):

    https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager


  • Registered Users, Registered Users 2 Posts: 1,453 ✭✭✭Sheepy99


    Just out of curiosity, what's the language called that's being used to style the UI? I know it follows an xml format, but I mean the syntax and all that comes with it. Is it just an extension of Java?


Advertisement