我正在使用Android Studio。
AQ版:编译组:'com.googlecode.android-query',名称:'android-query',版本:'0.25.9'
几个月前我在一个eclipse项目中使用了相同的技术并且它起作用了:(。
在片段的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时遇到了麻烦。
感谢所有回复!!!
答案 0 :(得分:2)
问题实际上在maven源代码中(编译组:'com.googlecode.android-query',名称:'android-query',版本:'0.25.9')。该库缺少一个html文件。解决方案是从https://code.google.com/p/android-query/downloads/list下载jar文件。
答案 1 :(得分:1)
如果您的应用定位> = SDK 18并在Android 4.4上运行,则WebView的onNewPicture回调将提供null图片;即,API旨在通知您内容何时更改但未向您提供图片。我不熟悉aQuery,但听起来他们需要更新他们的库来处理这种情况。