2

I'm using Android Studio.

AQ version : compile group: 'com.googlecode.android-query', name: 'android-query', version: '0.25.9'

I used the same technique in an eclipse project few months ago and it worked:(.

In fragment's onActivityCreated:

     aq = new AQuery(getActivity(), this.getView());
    String url = "http://farm4.static.flickr.com/3531/3769416703_b76406f9de.jpg";
    aq.id(R.id.image_webview).progress(R.id.progress).webImage(url);

I've tried to put the code into onCreateView with the same result.

Edited:

2-05 21:42:20.181  32489-32489/cz.bioport.interspar.androidd.debug W/AQuery﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[])' on a null object reference
        at com.androidquery.util.AQUtility.copy(AQUtility.java:401)
        at com.androidquery.util.AQUtility.copy(AQUtility.java:389)
        at com.androidquery.util.AQUtility.toBytes(AQUtility.java:421)
        at com.androidquery.util.WebImage.getSource(WebImage.java:48)
        at com.androidquery.util.WebImage.setup(WebImage.java:146)
        at com.androidquery.util.WebImage.access$100(WebImage.java:32)
        at com.androidquery.util.WebImage$1.onNewPicture(WebImage.java:131)
        at com.android.webview.chromium.WebViewContentsClientAdapter.onNewPicture(WebViewContentsClientAdapter.java:351)
        at com.android.org.chromium.android_webview.AwContentsClientCallbackHelper$1.handleMessage(AwContentsClientCallbackHelper.java:127)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4998)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
java.lang.NullPointerException:Attempt to invoke virtual method 'java.lang.String java.lang.String.replace(java.lang.CharSequence, java.lang.CharSequence)' on a null object reference
        at com.androidquery.util.WebImage.setup(WebImage.java:147)
        at com.androidquery.util.WebImage.access$100(WebImage.java:32)
        at com.androidquery.util.WebImage$1.onNewPicture(WebImage.java:131)
        at com.android.webview.chromium.WebViewContentsClientAdapter.onNewPicture(WebViewContentsClientAdapter.java:351)
        at com.android.org.chromium.android_webview.AwContentsClientCallbackHelper$1.handleMessage(AwContentsClientCallbackHelper.java:127)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4998)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)

AQ source code

private static String getSource(Context context){
    if(template == null){
        try{
            InputStream is = context.getClassLoader().getResourceAsStream("com/androidquery/util/web_image.html");          
            template = new String(AQUtility.toBytes(is));
        }catch(Exception e){
            AQUtility.debug(e);
        }
    }
    return template;
}
 private void setup(){
    String source = getSource(wv.getContext());
LINE 147:       String html = source.replace("@src", url).replace("@color", Integer.toHexString(color));
    .....
}

It looks like that AS is having troubles with loading web_image.html.

Thank you for all replies!!!

malinjir
  • 1,475
  • 2
  • 12
  • 17
  • It seems like `getSource(Context context)` returns null. Check what kind of exception occure in this function. – Denys Vasylenko Dec 05 '13 at 20:22
  • What android api level you are using? I heard Webview is changed in Kitkat (I haven't check it, but running the webview demo with the AQ demo app seems ok on Kitkat. There's also a chance that getSource return null but that's weird. It's either the javascript source file is missing from your project (or by some reason not packaged to the apk), or something related to class loader (unlikely). Check if /AndroidQuery/src/com/androidquery/util/web_image.html exists in your source. – Peter Liu Dec 06 '13 at 05:51
  • Hmm web_image.html is really missing from the jar file which I downloaded using maven... Thank you:) – malinjir Dec 07 '13 at 16:45

2 Answers2

2

The problem is actually in the maven source ( compile group: 'com.googlecode.android-query', name: 'android-query', version: '0.25.9'). The library is missing one of the html files. Solution is to download jar file from https://code.google.com/p/android-query/downloads/list .

malinjir
  • 1,475
  • 2
  • 12
  • 17
1

If your app is targeting >= SDK 18 and running on Android 4.4 then the WebView's onNewPicture callback will provide a null Picture; i.e. the API is intended to inform you when content has changed but doesn't give you the Picture. I'm not familiar with aQuery but it sounds like they need to update their libraries to handle this case.

ksasq
  • 4,424
  • 2
  • 18
  • 10
  • I tried to run the app on android 2.3 but I'm still getting NullPointerEx. Thank you for your post. – malinjir Dec 07 '13 at 16:38