0

에뮬레이터와 Android 장치 모두에서 cordova 응용 프로그램을 실행하는 데 문제가 있습니다.이 코드는 phonegap-template-react-hot-loader 템플릿으로 작성된 응용 프로그램입니다.코드 실행 응용 프로그램을 실행할 때 런타임 예외

E/AndroidRuntime(2704): FATAL EXCEPTION: main 
E/AndroidRuntime(2704): Process: com.cphoto.pl, PID: 2704 
E/AndroidRuntime(2704): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cphoto.pl/com.cphoto.pl.MainActivity}: java.lang.StringIndex 
OutOfBoundsException: length=0; index=0 
E/AndroidRuntime(2704):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
E/AndroidRuntime(2704):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
E/AndroidRuntime(2704):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
E/AndroidRuntime(2704):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
E/AndroidRuntime(2704):  at android.os.Handler.dispatchMessage(Handler.java:102) 
E/AndroidRuntime(2704):  at android.os.Looper.loop(Looper.java:136) 
E/AndroidRuntime(2704):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
E/AndroidRuntime(2704):  at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(2704):  at java.lang.reflect.Method.invoke(Method.java:515) 
E/AndroidRuntime(2704):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
E/AndroidRuntime(2704):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
E/AndroidRuntime(2704):  at dalvik.system.NativeStart.main(Native Method) 
E/AndroidRuntime(2704): Caused by: java.lang.StringIndexOutOfBoundsException: length=0; index=0 
E/AndroidRuntime(2704):  at org.apache.cordova.ConfigXmlParser.setStartUrl(ConfigXmlParser.java:139) 
E/AndroidRuntime(2704):  at org.apache.cordova.ConfigXmlParser.handleStartTag(ConfigXmlParser.java:116) 
E/AndroidRuntime(2704):  at org.apache.cordova.ConfigXmlParser.parse(ConfigXmlParser.java:75) 
E/AndroidRuntime(2704):  at org.apache.cordova.ConfigXmlParser.parse(ConfigXmlParser.java:63) 
E/AndroidRuntime(2704):  at org.apache.cordova.CordovaActivity.loadConfig(CordovaActivity.java:158) 
E/AndroidRuntime(2704):  at org.apache.cordova.CordovaActivity.onCreate(CordovaActivity.java:111) 
E/AndroidRuntime(2704):  at com.cphoto.pl.MainActivity.onCreate(MainActivity.java:30) 
E/AndroidRuntime(2704):  at android.app.Activity.performCreate(Activity.java:5231) 
E/AndroidRuntime(2704):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
E/AndroidRuntime(2704):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
E/AndroidRuntime(2704):  ... 11 more 
D/dalvikvm(2563): DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_ABIS 
W/dalvikvm(2563): VFY: unable to resolve static field 2750 (SUPPORTED_ABIS) in Landroid/os/Build; 
D/dalvikvm(2563): VFY: replacing opcode 0x62 at 0x0008 
D/dalvikvm(2563): GC_CONCURRENT freed 532K, 18% free 5407K/6528K, paused 12ms+9ms, total 39ms 
E/MDM  (2563): [120] pwk.a: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null} 
W/ActivityManager(1817): Force finishing activity com.cphoto.pl/.MainActivity 

의 AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?> 
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.cphoto.pl" 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:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true"> 
     <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize"> 
      <intent-filter android:label="@string/launcher_name"> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden"> 
      <intent-filter> 
       <action android:name="com.phonegap.plugins.barcodescanner.SCAN" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity android:label="@string/share_name" android:name="com.google.zxing.client.android.encode.EncodeActivity"> 
      <intent-filter> 
       <action android:name="com.phonegap.plugins.barcodescanner.ENCODE" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity android:label="@string/share_name" android:name="com.google.zxing.client.android.HelpActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.VIEW" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
    </application> 
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" /> 
    <uses-permission android:name="android.permission.CAMERA" /> 
    <uses-permission android:name="android.permission.FLASHLIGHT" /> 
    <uses-feature android:name="android.hardware.camera" android:required="false" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
</manifest> 

config.xml에

<?xml version='1.0' encoding='utf-8'?> 
<widget id="com.cphoto.pl" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"> 
    <name>Cphoto</name> 
    <description> 
     Cordova Photo React Hot Reloader 
    </description> 
    <author email="[email protected]" href="https://github.com/kmiasko"> 
     Kmiasko 
    </author> 
    <preference name="permissions" value="none" /> 
    <preference name="orientation" value="default" /> 
    <preference name="target-device" value="universal" /> 
    <preference name="DisallowOverscroll" value="true" /> 
    <preference name="detect-data-types" value="true" /> 
    <preference name="android-minSdkVersion" value="19" /> 
    <preference name="android-installLocation" value="auto" /> 
    <platform name="android"> 
...icons 
    </platform> 
    <platform name="ios"> 
...icons 
    </platform> 
    <platform name="wp8"> 
...icons 
    </platform> 
    <platform name="windows"> 
...icons 
    </platform> 
    <access origin="*" /> 
    <allow-intent href="http://*/*" /> 
    <allow-intent href="https://*/*" /> 
    <allow-intent href="tel:*" /> 
    <allow-intent href="sms:*" /> 
    <allow-intent href="mailto:*" /> 
    <allow-intent href="geo:*" /> 
    <platform name="android"> 
     <content src="" /> 
     <allow-intent href="market:*" /> 
     <allow-navigation href="*" /> 
    </platform> 
    <plugin name="cordova-plugin-whitelist" version="1" /> 
    <plugin name="cordova-plugin-statusbar" spec="~2.1.0" /> 
    <plugin name="cordova-plugin-console" spec="~1.0.4" /> 
    <plugin name="cordova-plugin-crosswalk-webview" spec="~2.1.0"> 
     <variable name="XWALK_VERSION" value="21+" /> 
     <variable name="XWALK_LITEVERSION" value="xwalk_core_library_canary:17+" /> 
     <variable name="XWALK_COMMANDLINE" value="--disable-pull-to-refresh-effect" /> 
     <variable name="XWALK_MODE" value="embedded" /> 
     <variable name="XWALK_MULTIPLEAPK" value="true" /> 
    </plugin> 
    <plugin name="cordova-plugin-camera" spec="~2.3.0" /> 
    <engine name="android" spec="~5.2.2" /> 
</widget> 
+0

Pls는 com.cphoto.pl.MainActivity 클래스의 줄 30에서 예외 인 StringIndexOutOfBoundsException이 발생하므로 com.cphoto.pl.MainActivity에 대한 코드를 제공합니다. –

+0

나는 그것이 여러분에게 아무 것도 알려 줄 것이라고 생각하지 않습니다. cordova android 플랫폼이 생성되었습니다. 파일. 'import android.os.Bundle; import org.apache.cordova. *; 공용 클래스 MainActivity는 CordovaActivity 연장 { @Override 공개 무효에서 onCreate (번들 savedInstanceState) { super.onCreate (savedInstanceState); // config.xml의 에 의해 설정 loadUrl (launchUrl); } }' – kmiasko

답변

0

문제는 템플릿에서 NPM 스크립트 설정을 수정 한 것이 었습니다 :

는 여기 ADB 로그입니다. xxx 및 변경됨 <content src="index.html" /> to <content src="http://10.0.2.2:8080" /> 그래서 안드로이드 장치/에뮬레이터는 index.html 파일과 함께 제공되지 않았습니다.

관련 문제