Android上的Cordova CLI 4.3.0加载URL崩溃

时间:2015-06-23 10:09:58

标签: android cordova-cli cordova-4

Cordova CLI 4.3.0混合应用程序在Android平台上使用index.html在loadURL上崩溃 在Android平台上的混合应用程序崩溃中加载Cordova Webview上的任何html

MainActivity.java:

package com.example.helloWorld;
import org.apache.cordova.DroidGap; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
public class MainAcitivity extends DroidGap { 
   public static SharedPreferences prefs; 
   public static Handler customHandler = new Handler(); 

   @Override public void onCreate(Bundle savedInstanceState) {     
   super.onCreate(savedInstanceState);
   super.setIntegerProperty("splashscreen", R.drawable.splash); 
   super.loadUrl("file:///android_asset/www/index.html");
   } 
}

下面是stacktrace

06-23 15:25:31.425: E/AndroidRuntime(18725): FATAL EXCEPTION: main
06-23 15:25:31.425: E/AndroidRuntime(18725): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloWorld/com.example.helloWorld.MainActivity}: java.lang.NullPointerException
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.os.Looper.loop(Looper.java:176)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.ActivityThread.main(ActivityThread.java:5419)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at java.lang.reflect.Method.invokeNative(Native Method)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at java.lang.reflect.Method.invoke(Method.java:525)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at dalvik.system.NativeStart.main(Native Method)
06-23 15:25:31.425: E/AndroidRuntime(18725): Caused by: java.lang.NullPointerException
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:195)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:116)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.PluginManager.init(PluginManager.java:92)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.CordovaWebView.init(CordovaWebView.java:163)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:345)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:320)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:362)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at com.example.helloWorld.MainActivity.onCreate(MainActivity.java:59)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.Activity.performCreate(Activity.java:5372)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
06-23 15:25:31.425: E/AndroidRuntime(18725):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)

1 个答案:

答案 0 :(得分:0)

尝试使用 CordovaActivity 进行扩展

import org.apache.cordova.Config;
import org.apache.cordova.CordovaActivity;

public class MyKnovelToGo extends CordovaActivity
{
    public static SharedPreferences prefs; 
   public static Handler customHandler = new Handler(); 

   @Override 
   public void onCreate(Bundle savedInstanceState) {     
     super.onCreate(savedInstanceState);
     super.setIntegerProperty("splashscreen", R.drawable.splash); 
     super.loadUrl("file:///android_asset/www/index.html");
   } 
}

在Android Manifest中, 对于应用程序名称,请使用包名称定义,如此

 android:name="com.example.package.MainActivity"