0

I am using fragments in Android.I got an NoClassDefFoundException while clicking the button. The code given below.

MainActivity.class

public void onClick(View view) {
    // TODO Auto-generated method stub
    if(view.equals(btnLogin)){
        Intent logd=new Intent(getApplicationContext(), Home.class);
        startActivity(logd);
    }

Home.class

package com.nv.netpos;
import java.util.Stack;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
public class Home extends SherlockFragmentActivity {
    private FragmentTabHost tabHost;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        tabHost=(FragmentTabHost)findViewById(android.R.id.tabhost);
        tabHost.setup(getApplicationContext(), getSupportFragmentManager());
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("HOME"),
             Fragment2.class, null);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("ITEMS"),
                Fragment2.class, null);
}}
Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30
jithin
  • 11
  • 3

2 Answers2

1

Your problem is probably that you didnt declare Home activity in your AndroidManifest.xml.

See AndroidManifest documentation or this topic to learn how to declare activity in manifest.

Note: as @GrIsHu pointed out in comments, dont use getApplicationContext(), use getApplication() when passing context parameter.

Community
  • 1
  • 1
hendrix
  • 3,364
  • 8
  • 31
  • 46
0

Try this:

Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it.Mark all checkboxes.Click on Apply and clean the project.

This worked for me.Hope this helps.

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69