android - 使用 NullPointerEx 中的查询结果将图像加载到 Web View 中

标签 android android-webview aquery

我正在使用 Android Studio。

AQ 版本:编译组:'com.googlecode.android-query',名称:'android-query',版本:'0.25.9'

几个月前我在 Eclipse 项目中使用了相同的技术并且它有效:(。

在fragment的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);

我尝试将代码放入 onCreateView 中,得到相同的结果。

编辑:

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源代码

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));
    .....
}

AS 似乎在加载 web_image.html 时遇到问题。

谢谢大家的回复!!!

最佳答案

问题实际上出在maven源中(编译组:'com.googlecode.android-query',名称:'android-query',版本:'0.25.9')。该库缺少 html 文件之一。解决办法是从https://code.google.com/p/android-query/downloads/list下载jar文件.

关于android - 使用 NullPointerEx 中的查询结果将图像加载到 Web View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20409636/

相关文章:

android - 平滑滚动在 ViewPager 中不起作用(支持库)

android - firebase 控制台中的项目已消失,但应用程序运行良好

android - 如何从 webview 上传图片?

android - AQuery 从图库中选择图像

android - MoPub SDK : how to remove the video ads ?

android - ICS 中脱节的 WebView 绘图

android - activityForResult 按钮返回时的 WebView 不起作用

Android查询网络错误-101

android - 从 SD 卡加载视频缩略图的位图

android - 记事本问题 : getIntent() and set data (by reference? )