mmmm
mmmm

Reputation: 3938

Unfortunately HelloWorld has stopped ( Android )

I'm following this tutorial: http://mobile.tutsplus.com/tutorials/phonegap/phonegap-from-scratch/ ( on windows )

and I get the message from the tittle. I don't know if this changes anything ( don't think so ) but my files from phonegap are called cordova.js and cordova.jar. I only changed in the index.html route for cordova.js. Also - I don't know if my phone-device in phonegap is correctly configured ( but on the other hand - i don't know how could I screw it ). The emulator is starting but when I click on my app it shows.. THE message.

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hello.world"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="7" />

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:resizeable="true"
    android:anyDensity="true"
    />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="hello.world.FullscreenActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

FullscreenActivity.java ( with some of the comments removed )

package hello.world;

import hello.world.util.SystemUiHider;
import org.apache.cordova.DroidGap;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

public class FullscreenActivity extends DroidGap {

private static final boolean AUTO_HIDE = true;
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
private static final boolean TOGGLE_ON_CLICK = true;
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
private SystemUiHider mSystemUiHider;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    super.loadUrl("file:///android_asset/www/index.html");

    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    final View contentView = findViewById(R.id.fullscreen_content);

    mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider
            .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                // Cached values.
                int mControlsHeight;
                int mShortAnimTime;

                @Override
                @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                public void onVisibilityChange(boolean visible) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                         if (mControlsHeight == 0) {
                            mControlsHeight = controlsView.getHeight();
                        }
                        if (mShortAnimTime == 0) {
                            mShortAnimTime = getResources().getInteger(
                                    android.R.integer.config_shortAnimTime);
                        }
                        controlsView.animate()
                                .translationY(visible ? 0 : mControlsHeight)
                                .setDuration(mShortAnimTime);
                    } else {
                         controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
                    }

                    if (visible && AUTO_HIDE) {
                        // Schedule a hide().
                        delayedHide(AUTO_HIDE_DELAY_MILLIS);
                    }
                }
            });

    contentView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TOGGLE_ON_CLICK) {
                mSystemUiHider.toggle();
            } else {
                mSystemUiHider.show();
            }
        }
    });

       findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

      delayedHide(100);
}

 View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (AUTO_HIDE) {
            delayedHide(AUTO_HIDE_DELAY_MILLIS);
        }
        return false;
    }
};

Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
    @Override
    public void run() {
        mSystemUiHider.hide();
    }
};

private void delayedHide(int delayMillis) {
    mHideHandler.removeCallbacks(mHideRunnable);
    mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}

EDIT:

LogCat

1

2-06 07:51:43.490: I/CordovaLog(799): Changing log level to DEBUG(3)
12-06 07:51:43.500: I/CordovaLog(799): Found preference for useBrowserHistory=true
12-06 07:51:43.500: D/CordovaLog(799): Found preference for useBrowserHistory=true
12-06 07:51:43.500: I/CordovaLog(799): Found preference for exit-on-suspend=false
12-06 07:51:43.500: D/CordovaLog(799): Found preference for exit-on-suspend=false
12-06 07:51:43.500: D/DroidGap(799): DroidGap.onCreate()
12-06 07:51:43.860: V/WebViewChromium(799): Binding Chromium to the main looper Looper{b1d30dd0}
12-06 07:51:43.880: I/chromium(799): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
12-06 07:51:43.930: I/BrowserProcessMain(799): Initializing chromium process, renderers=0
12-06 07:51:44.320: E/chromium(799): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
12-06 07:51:44.320: E/chromium(799): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
12-06 07:51:44.320: E/chromium(799): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
12-06 07:51:44.340: E/chromium(799): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
12-06 07:51:44.340: E/chromium(799): [ERROR:gpu_info_collector.cc(86)] gfx::GLSurface::InitializeOneOff() failed
12-06 07:51:44.420: W/chromium(799): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
12-06 07:51:44.820: D/dalvikvm(799): GC_FOR_ALLOC freed 68K, 5% free 3033K/3168K, paused 330ms, total 333ms
12-06 07:51:44.840: I/dalvikvm-heap(799): Grow heap (frag case) to 4.095MB for 1127536-byte allocation
12-06 07:51:45.020: D/dalvikvm(799): GC_FOR_ALLOC freed 1K, 4% free 4133K/4272K, paused 175ms, total 175ms
12-06 07:51:45.490: D/CordovaWebView(799): CordovaWebView is running on device made by: unknown
12-06 07:51:45.530: D/JsMessageQueue(799): Set native->JS mode to 2
12-06 07:51:45.570: D/DroidGap(799): DroidGap.init()
12-06 07:51:45.610: D/CordovaWebView(799): >>> loadUrl(file:///android_asset/www/index.html)
12-06 07:51:45.610: D/PluginManager(799): init()
12-06 07:51:45.630: D/CordovaWebView(799): >>> loadUrlNow()
12-06 07:51:45.980: D/AndroidRuntime(799): Shutting down VM
12-06 07:51:45.980: W/dalvikvm(799): threadid=1: thread exiting with uncaught exception (group=0xb1a5cb90)
12-06 07:51:46.090: E/AndroidRuntime(799): FATAL EXCEPTION: main
12-06 07:51:46.090: E/AndroidRuntime(799): Process: hello.world, PID: 799
12-06 07:51:46.090: E/AndroidRuntime(799): java.lang.RuntimeException: Unable to start activity ComponentInfo{hello.world/hello.world.FullscreenActivity}: java.lang.NullPointerException
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.os.Looper.loop(Looper.java:137)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.ActivityThread.main(ActivityThread.java:4998)
12-06 07:51:46.090: E/AndroidRuntime(799):  at java.lang.reflect.Method.invokeNative(Native Method)
12-06 07:51:46.090: E/AndroidRuntime(799):  at java.lang.reflect.Method.invoke(Method.java:515)
12-06 07:51:46.090: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-06 07:51:46.090: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-06 07:51:46.090: E/AndroidRuntime(799):  at dalvik.system.NativeStart.main(Native Method)
12-06 07:51:46.090: E/AndroidRuntime(799): Caused by: java.lang.NullPointerException
12-06 07:51:46.090: E/AndroidRuntime(799):  at hello.world.util.SystemUiHiderHoneycomb.setup(SystemUiHiderHoneycomb.java:74)
12-06 07:51:46.090: E/AndroidRuntime(799):  at hello.world.FullscreenActivity.onCreate(FullscreenActivity.java:61)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.Activity.performCreate(Activity.java:5243)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-06 07:51:46.090: E/AndroidRuntime(799):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-06 07:51:46.090: E/AndroidRuntime(799):  ... 11 more
12-06 07:52:30.250: I/Process(799): Sending signal. PID: 799 SIG: 9

Upvotes: 0

Views: 3483

Answers (1)

cgalvao1993
cgalvao1993

Reputation: 148

It's weird, the tutorial you mentioned has no "setContentView(R.layout.layoutname)", which is required by every activity. If you don't use it, the compiler will never know which layout to display. Your onCreate method should start like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");
    setContentView(R.layout.layoutname);
    ....

Upvotes: 1

Related Questions