1
我的應用程序具有接片和一個標籤包含一個片段。片段中有一個卡片視圖。我想當我點擊cardview時,我想讓webview像this一樣工作,但是我收到錯誤消息。 我webview.xml在適配器使用網頁視圖
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/mywebview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我的數據適配器
public static class ContentViewHolder extends RecyclerView.ViewHolder {
protected TextView title;
protected TextView description;
protected TextView date;
protected ImageView imgSrc;
protected String urlS;
protected int itemPos;
WebView mWebView;
AdvancedWebView vw;
public ContentViewHolder(View v) {
super(v);
title = (TextView) v.findViewById(R.id.title);
description = (TextView) v.findViewById(R.id.descript);
date = (TextView) v.findViewById(R.id.date);
imgSrc=(ImageView)v.findViewById(R.id.thumbnail);
v.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
/*Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlS));
v.getContext().startActivity(myIntent);*/
//there is a problem
mWebView =(WebView)v.findViewById(R.id.mywebview);
mWebView.loadUrl("http://www.google.com");
}
});
}
}
錯誤
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.oguz.topluluk, PID: 3449
java.lang.NullPointerException
at com.example.oguz.topluluk.WebDataAdapter$ContentViewHolder$1.onClick(WebDataAdapter.java:113)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
我怎樣才能解決這個問題?我是Android新手。你能指導我嗎?