我正在尝试启动我的Cordova 3应用程序,但似乎我遇到了一些问题。
错误日志:
09-28 18:03:05.538: E/AndroidRuntime(25370): FATAL EXCEPTION: main
09-28 18:03:05.538: E/AndroidRuntime(25370): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fourgamers.reader/com.fourgamers.reader.FourGamers}: java.lang.NullPointerException
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.ActivityThread.access$600(ActivityThread.java:140)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.os.Looper.loop(Looper.java:137)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-28 18:03:05.538: E/AndroidRuntime(25370): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 18:03:05.538: E/AndroidRuntime(25370): at java.lang.reflect.Method.invoke(Method.java:511)
09-28 18:03:05.538: E/AndroidRuntime(25370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
09-28 18:03:05.538: E/AndroidRuntime(25370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
09-28 18:03:05.538: E/AndroidRuntime(25370): at dalvik.system.NativeStart.main(Native Method)
09-28 18:03:05.538: E/AndroidRuntime(25370): Caused by: java.lang.NullPointerException
09-28 18:03:05.538: E/AndroidRuntime(25370): at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:374)
09-28 18:03:05.538: E/AndroidRuntime(25370): at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:338)
09-28 18:03:05.538: E/AndroidRuntime(25370): at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:451)
09-28 18:03:05.538: E/AndroidRuntime(25370): at com.fourgamers.reader.FourGamers.onCreate(FourGamers.java:31)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.Activity.performCreate(Activity.java:5206)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
09-28 18:03:05.538: E/AndroidRuntime(25370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
09-28 18:03:05.538: E/AndroidRuntime(25370): ... 11 more
FourGamers.java
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package com.fourgamers.reader;
import android.os.Bundle;
import org.apache.cordova.*;
public class FourGamers extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl(Config.getStartUrl(), 10000);
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
}
}
的AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="com.fourgamers.reader" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="FourGamers" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />
</manifest>
非常感谢任何帮助。
谢谢。
答案 0 :(得分:3)
查看CordobaActivity
的源代码,我怀疑问题是您在调用loadUrl
之前使用super.onCreate
,这意味着活动的各个方面还没有联系起来。我建议你绕过这条线:
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl(Config.getStartUrl(), 10000);
(顺便说一下,为什么你要拨打super.loadUrl(Config.getStartUrl())
两次,一次是超时,一次是没有......)