Issue
This should really be easy for an experienced android programmer. Unfortunately I don't know anything about the android sdk. I am using PhoneGap to package a web app and I need to override the WebSettings in the cordovaExample.java (right now I am using the cordovaExample as a template for my app). My code looks like this:
package org.apache.cordova.example;
import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;
public class cordovaExample extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{
this.appView.getSettings().setUseWideViewPort(true);
this.appView.getSettings().setLoadWithOverviewMode(true);
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
I can run ant debug install
without a problem but when I start the app in the emulator, the following errors occur:
E/AndroidRuntime( 549): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.apache.cordova.example/org.apache.cordova.example.cordovaExample}: java.lang.NullPointerException
E/AndroidRuntime( 549): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime( 549): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 549): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 549): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 549): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 549): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 549): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 549): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 549): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 549): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 549): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 549): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 549): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 549): at org.apache.cordova.example.cordovaExample.onCreate(cordovaExample.java:12)
E/AndroidRuntime( 549): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 549): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 549): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime( 549): ... 11 more
W/ActivityManager( 78): Force finishing activity org.apache.cordova.example/.cordovaExample
The errors occur no matter if I package for android sdk 2.1 or 4.3 (on Mac OS X Lion).
Any help will be very much appreciated.
Solution
The error says that there is a NullPointerException at line 12:
this.appView.getSettings().setUseWideViewPort(true);
Either this.appView is null of appView.getSettings() is returning null. Add null value checks and see which one it is. It will be easier to find out why there is a null value there once you know which one it is.
Also, nothing to do with the problem and not sure if it is a typo but your class name is camel cased. It is against best practice to do that. It will confuse you in the future to do that since camel case nomenclature is used with instance variables, members, and methods only. Class names are always Initial letter uppercased and package names are always lowercase. So it should be
CordovaExample
and not
cordovaExample
Answered By - praneetloke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.