フラグメントを使用して webView を実装したいのですが、.xml は次のようになります。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<webView
android:id="@+id/webView01"
android:layout_width="wrap_content"
android:layout_height="450dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<webView
android:id="@+id/webView02"
android:layout_width="180dp"
android:layout_height="50dp"
/>
<webView
android:id="@+id/webView03"
android:layout_width="180dp"
android:layout_height="50dp"/>
</LinearLayout>
</LinearLayout>
そして、私がwebviewを扱う方法は、 public class SelectionFragment extends Fragment{ のようなものです
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState){
super.onCreateView(inflater,container,savedInstanceState);
View view =inflater.inflate(R.layout.selected,container,false);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
WebView webView1=(WebView) getView().findViewById(R.id.webView01);
String url="#######";
String url1="####"; String url2="#######";
webView1.setWebViewClient(new Callback());
webView1.loadUrl(url);
WebView webView2=(WebView)getView().findViewById(R.id.webView02);
WebView webView3=(WebView)getView().findViewById(R.id.webView03);
webView2.loadUrl(url1);
webView3.loadUrl(url2);
}
private class Callback extends WebViewClient{
public boolean shouldOverrideUrlLoading(WebView view, String url){
return(false);
}
}
アプリケーションを実行すると、エラーが表示されます
08-01 18:45:39.426: E/AndroidRuntime(27086): FATAL EXCEPTION: main
08-01 18:45:39.426: E/AndroidRuntime(27086): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rulee.logintested/com.rulee.logintested.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.os.Looper.loop(Looper.java:130)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.ActivityThread.main(ActivityThread.java:3691)
08-01 18:45:39.426: E/AndroidRuntime(27086): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 18:45:39.426: E/AndroidRuntime(27086): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 18:45:39.426: E/AndroidRuntime(27086): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
08-01 18:45:39.426: E/AndroidRuntime(27086): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
08-01 18:45:39.426: E/AndroidRuntime(27086): at dalvik.system.NativeStart.main(Native Method)
08-01 18:45:39.426: E/AndroidRuntime(27086): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-01 18:45:39.426: E/AndroidRuntime(27086): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.Activity.setContentView(Activity.java:1663)
08-01 18:45:39.426: E/AndroidRuntime(27086): at com.rulee.logintested.MainActivity.onCreate(MainActivity.java:41)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-01 18:45:39.426: E/AndroidRuntime(27086): ... 11 more
08-01 18:45:39.426: E/AndroidRuntime(27086): Caused by: java.lang.NullPointerException
08-01 18:45:39.426: E/AndroidRuntime(27086): at com.rulee.logintested.SelectionFragment.onCreate(SelectionFragment.java:38)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.support.v4.app.Fragment.performCreate(Fragment.java:1437)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:877)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
08-01 18:45:39.426: E/AndroidRuntime(27086): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-01 18:45:39.426: E/AndroidRuntime(27086): ... 20 more
しかし、.xml を変更し、webView を単純な TextView に変更し、webView を処理するコードを削除すると、エラーが修正されました。誰でも私にいくつかのアイデアを提供できますか?
ありがとう