无法实例化活动:android webview中的Nullpointerexception

时间:2015-07-22 05:25:23

标签: android webview

我试图运行示例代码在Android 5.1模拟器中启动应用程序时,我收到了NULL POINTER EXCEPTION的错误....任何人都有一些提示..我的活动文件在ANDroid清单文件中注册但是2我的班级是他们没有注册的片段

MainActivity.class
public class MainActivity extends Activity implements TabListener {
WebView webView;
Button button;
MainFragment mainFragment;
ImageButton imageButton;
TextView txtview;
EditText editText;
JavaScriptInterface jSInterface;
ActionBar bar = getActionBar();
@SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override
 protected void onCreate(Bundle savedInstanceState) {
    Log.d("Main Activity", "Inside on create");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setStatusBarColor(this, Color.parseColor("#4CAF50"));


    webView = (WebView) findViewById(R.id.webPage);
    webView.getSettings().setJavaScriptEnabled(true);
    jSInterface = new JavaScriptInterface(this);
    webView.addJavascriptInterface(jSInterface, "JSInterface");
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.setWebChromeClient(new WebChromeClient());
    System.out.println("Opening webview");
    webView.loadUrl("file:///android_asset/index2.html");

    Tab tab1 = bar.newTab();
    tab1.setText("tab1");
    tab1.setTabListener(this);
    bar.addTab(tab1);

    Tab tab2 = bar.newTab();
    tab2.setText("tab2");
    tab2.setTabListener(this);
    bar.addTab(tab2);

    Tab tab3 = bar.newTab();
    tab3.setText("tab3");
    tab3.setTabListener(this);
    bar.addTab(tab3);
    imageButton=(ImageButton)findViewById(R.id.imagebutton1);
    editText=(EditText)findViewById(R.id.editText1);
    Fragment main = new MainFragment();
    mainFragment=(MainFragment)main;
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, main);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.addToBackStack(null);
    ft.commit();
      }

1 个答案:

答案 0 :(得分:0)

试试这个

<activity android:name=".activities.MainActivity"/>

您的清单文件出错了,如果您在此处发布清单文件内容,将很容易解决。