简体   繁体   English

科尔多瓦3,无法开始活动

[英]Cordova 3, Unable to start activity

I am trying to start my Cordova 3 application, but it seems I am running into some problems. 我正在尝试启动Cordova 3应用程序,但似乎遇到了一些问题。

Error log: 错误日志:

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 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 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>

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thank you. 谢谢。

Looking at the source code for CordobaActivity , I suspect the problem is that you're using loadUrl before you've called super.onCreate , which means various aspects of the activity aren't hooked up yet. 综观的源代码CordobaActivity ,我怀疑的问题是,你使用loadUrl你调用之前super.onCreate ,这意味着活动的各个方面不勾搭上了呢。 I suggest you switch round the lines, to this: 我建议您改行:

super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl(Config.getStartUrl(), 10000);

(It's not clear why you're calling super.loadUrl(Config.getStartUrl()) twice, by the way - once with a timeout and once without...) (尚不清楚为什么您要两次调用super.loadUrl(Config.getStartUrl()) -一次超时,一次不调用...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM