我一直在使用相同的方法来膨胀所有其他 fragment 中的所有其他小部件,但由于某种原因它在这里不起作用。
ResultFragment.java:
public class ResultFragment extends Fragment {
private WebView webPageResult;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_question, parent, false);
webPageResult = (WebView) v.findViewById(R.id.webPageResult);
webPageResult.loadUrl("google.com");
return v;
}
}
fragment_result.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.danielbalagula.gift.ResultFragment">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webPageResult"
android:layout_gravity="center_horizontal|bottom"/>
</FrameLayout>
最佳答案
您正在膨胀错误的布局,请尝试膨胀 fragment_result
而不是 fragment_question
。
使用View v = inflater.inflate(R.layout.fragment_result,parent, false);
关于java - 尝试在空对象引用上调用虚拟方法 'int android.webkit.WebView.loadUrl()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31923257/