简体   繁体   中英

NullPointerException on Cordova app

When i launch my cordova app in android 4.3+, i have no problems.

But when i launch my app on android 4.1.2 i have a nullpointerexception and after first action on app, app exit.

Last call is a callback function :

var callback = function(){
        $location.path('/profils');
    };

and when "/profils" is launched, getProfils service method is called:

service.factory('HttpService', ['$http', '$location',
    function($http, $location){
        return {
            getProfils: function(){
                console.log('-> Get Profils');
                uiUtils.showLoader();
                return $http.get(URL).
                    then(
                        function success(response) { 
                            uiUtils.hideLoader(); 
                            return response.data.Result; 
                        },
                        function error(reason) { 
                            uiUtils.hideLoader(); 
                            return false; 
                        }
                    );
            },
...

You can see stacktrace below :

I/Web Console( 8801): -> Get Profils:14

D/FirewallPolicy( 2128): getURLFilterEnabled(true)

D/FirewallPolicy( 2128): isUrlBlocked - Policy disabled

D/STATUSBAR-NetworkController( 2265): refreshSignalCluster: data=0 bt=false

I/ClipboardServiceEx( 2128): Send intent for dismiss clipboard dialog inside hideCurrentInputLocked() !

E/dalvikvm( 8801): Class lookup Landroid/webkit/WebResourceResponse; attempted with exception pending

W/dalvikvm( 8801): Pending exception is:

I/dalvikvm( 8801): java.lang.NullPointerException:

I/dalvikvm( 8801):  at android.content.res.AssetManager.openAsset(Native Method)

I/dalvikvm( 8801):  at android.content.res.AssetManager.open(AssetManager.java:315)

I/dalvikvm( 8801):  at android.webkit.BrowserFrame.inputStreamForAndroidResource(BrowserFrame.java:849)

I/dalvikvm( 8801):  at android.webkit.BrowserFrame.shouldInterceptRequest(BrowserFrame.java:939)

I/dalvikvm( 8801):  at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)

I/dalvikvm( 8801):  at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)

I/dalvikvm( 8801):  at android.os.Handler.dispatchMessage(Handler.java:99)

I/dalvikvm( 8801):  at android.os.Looper.loop(Looper.java:137)

I/dalvikvm( 8801):  at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:1067)

I/dalvikvm( 8801):  at java.lang.Thread.run(Thread.java:856)

I/dalvikvm( 8801): DALVIK THREADS:

I/dalvikvm( 8801): (mutexes: tll=0 tsl=0 tscl=0 ghl=0)

I/dalvikvm( 8801): 

I/dalvikvm( 8801): "main" prio=5 tid=1 NATIVE

I/dalvikvm( 8801):   | group="main" sCount=0 dsCount=0 obj=0x40eb2508 self=0x40e01b08

I/dalvikvm( 8801):   | sysTid=8801 nice=0 sched=0/0 cgrp=apps handle=1075203888

I/dalvikvm( 8801):   | schedstat=( 645744814 318546031 1496 ) utm=45 stm=19 core=1

I/dalvikvm( 8801):   #00  pc 0000da70  /system/lib/libc.so (epoll_wait+12)

I/dalvikvm( 8801):   #01  pc 00014899  /system/lib/libutils.so (android::Looper::pollInner(int)+96)

I/dalvikvm( 8801):   #02  pc 00014b01  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+104)

I/dalvikvm( 8801):   #03  pc 00063553  /system/lib/libandroid_runtime.so (android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22)

I/dalvikvm( 8801):   #04  pc 0001df30  /system/lib/libdvm.so (dvmPlatformInvoke+112)

I/dalvikvm( 8801):   #05  pc 0004d183  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+394)

I/dalvikvm( 8801):   #06  pc 00027360  /system/lib/libdvm.so

I/dalvikvm( 8801):   #07  pc 0002bc68  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)

I/dalvikvm( 8801):   #08  pc 0005fbb7  /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+374)

I/dalvikvm( 8801):   #09  pc 00067165  /system/lib/libdvm.so

I/dalvikvm( 8801):   #10  pc 00027360  /system/lib/libdvm.so

I/dalvikvm( 8801):   #11  pc 0002bc68  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)

I/dalvikvm( 8801):   #12  pc 0005f8f1  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+272)

I/dalvikvm( 8801):   #13  pc 00049773  /system/lib/libdvm.so

I/dalvikvm( 8801):   #14  pc 0004c4a1  /system/lib/libandroid_runtime.so

I/dalvikvm( 8801):   #15  pc 0004d663  /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+390)

I/dalvikvm( 8801):   #16  pc 00000dcf  /system/bin/app_process

I/dalvikvm( 8801):   #17  pc 00017123  /system/lib/libc.so (__libc_init+38)

I/dalvikvm( 8801):   #18  pc 00000b34  /system/bin/app_process

I/dalvikvm( 8801):   at android.os.MessageQueue.nativePollOnce(Native Method)

I/dalvikvm( 8801):   at android.os.MessageQueue.next(MessageQueue.java:125)

I/dalvikvm( 8801):   at android.os.Looper.loop(Looper.java:124)

I/dalvikvm( 8801):   at android.app.ActivityThread.main(ActivityThread.java:4921)

I/dalvikvm( 8801):   at java.lang.reflect.Method.invokeNative(Native Method)

I/dalvikvm( 8801):   at java.lang.reflect.Method.invoke(Method.java:511)

I/dalvikvm( 8801):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)

I/dalvikvm( 8801):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)

I/dalvikvm( 8801):   at dalvik.system.NativeStart.main(Native Method)

I/dalvikvm( 8801): 

Does any one have an idea how to solve it?

I have more logs if needed, but i think this is enought...but maybe not because i can't find the origin of the problem.

UPDATE :

After cleaning all the code, I found the exact error source :

<img    src="{{profil.selection ? profil.template.selectedPicture : profil.template.picture}}"/>

For the moment, don't know if error come from ternary or urls...

Error was really not explicit but i found the problem :

I use AngularJs in my cordova app and tried to display this next line :

<img    src="{{profil.selection ? profil.template.selectedPicture : profil.template.picture}}"/>

BUT :

"Using Angular markup like {{hash}} in a src attribute doesn't work right"

from the AngularJS documentation : https://docs.angularjs.org/api/ng/directive/ngSrc

So, i my browser and during my tests and dev i had no problem with that, but when i build it with cordova, my app crashed and exited with error above.

I think it's a bug to link with @JoffreyMaheo comment : https://issues.apache.org/jira/browse/CB-2391 , because {{hash}} is not interpreted, image url is not recognized and make a null pointer exception.

To correct it : we have to use "ng-src" and everything work with it :

<img    ng-src="{{profil.selection ? profil.template.selectedPicture : profil.template.picture}}"/>

I think this problem comes in Cordova when the URLs contain special characters.

So, be careful with special characters in URLs !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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