1

I was trying to run a sample code While launching the application in the android 5.1 emulator , I got error of NULL POINTER EXCEPTION.... Any one have some hint..MY ACTIVITY FILE IS REGISTERED IN ANDroid manifest file but 2 of my class are fragments they are not registered

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();
      }
Loren
  • 320
  • 1
  • 10
  • 25
  • Show Logcat and also Extend your Class with AppCompatActivity. – Shvet Jul 22 '15 at 05:26
  • my logcat is same as http://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo but the solutions mentioned here are not working for me – Loren Jul 22 '15 at 05:29
  • can you please debug your code and tell us in which line you get `NullPointerException` or please post logcat log here so that we can get the line. – Anand Singh Jul 22 '15 at 05:42

1 Answers1

0

try this

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

It is something your doing wrong with your manifest file, It will be easy to resolve if you post your manifest file contents here.