我从MainActivity调用MyWebView时未创建我的视图。它在logcat中给出了错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.com/com.abc.com.MainActivity}:
android.view.InflateException: Binary XML file line #31: Error inflating class com.abc.com.MyWebView
主要活动 -
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MyWebView (this,getApplicationContext());
}
}
public class MyWebView extends WebView{
public MyWebView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
WebView mwebview;
Activity act;
String webView_url;
RelativeLayout layout;
public MyWebView(Activity _acActivity, Context _cont) {
super(_cont);
act = _acActivity;
_context = _cont;
ViewGroup wkll = new ViewGroup(_context) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
}
};
LinearLayout.LayoutParams tlp =
new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT );
mwebview = new MyWebView(_context);
wkll.addView(mwebview);
mwebview.setLayoutParams(tlp);
mwebview.loadUrl("http://www.google.com");
}
}