我正在使用安卓工作室。
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 时遇到了问题。
谢谢大家的回复!!!