title: java.lang.ClassCastException in a Fragment
body: <p>Please find the below error and its code!! The first one contains the exception that I got while running the code, the remaining are the codes that I have used.</p>
  
  <blockquote>
    <p>Error:
        java.lang.ClassCastException: com.example.swethaa.myapp.MainPage cannot be cast to com.example.swethaa.myapp.entdb
        at com.example.swethaa.myapp.entrepreneurtab.onCreateView(entrepreneurtab.java:30)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2199)
        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)
        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:167)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1236)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1084)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
        at android.view.View.measure(View.java:18827)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
        at android.view.View.measure(View.java:18827)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
        at android.view.View.measure(View.java:18827)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
        at android.view.View.measure(View.java:18827)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:18827)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
        at android.view.View.measure(View.java:18827)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
        at android.view.View.measure(View.java:18827)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2136)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1248)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1484)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6064)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
        at android.view.Choreographer.doCallbacks(Choreographer.java:672)
        at android.view.Choreographer.doFrame(Choreographer.java:608)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
        at android.os.Handler.handleCallback(Handler.java:742)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5555)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)</p>
  </blockquote>
  
  <p><strong>MainPage.java</strong></p>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
  package com.example.swethaa.myapp;
  import android.os.Bundle;
  import android.support.design.widget.TabLayout;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.content.Intent;
  
  public class MainPage extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.home);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
          tabLayout.addTab(tabLayout.newTab().setText("Attorney"));
          tabLayout.addTab(tabLayout.newTab().setText("Entrepreneur"));
          tabLayout.addTab(tabLayout.newTab().setText("Investor"));
          tabLayout.addTab(tabLayout.newTab().setText("Job Seeker"));
          tabLayout.addTab(tabLayout.newTab().setText("Blog"));
          //tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
  
          final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
          final PagerAdapter adapter = new PagerAdapter
                  (getSupportFragmentManager(), tabLayout.getTabCount());
          viewPager.setAdapter(adapter);
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
          tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
  
              }
          });
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>
  
  <p><strong>entrepreneurtab.java</strong></p>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
  package  com.example.swethaa.myapp;
  
          import android.content.Context;
          import android.database.Cursor;
          import android.os.Bundle;
          import android.support.v4.app.Fragment;
          import android.support.v7.app.AppCompatActivity;
          import android.view.LayoutInflater;
          import android.view.View;
          import android.view.ViewGroup;
          import android.widget.TableLayout;
          import android.widget.TableRow;
          import android.widget.TableRow.LayoutParams;
          import android.widget.TextView;
          import android.widget.Toast;
          import android.graphics.Color;
          import android.graphics.Typeface;
          import android.support.annotation.NonNull;
          import android.support.v4.content.ContextCompat;
  
  public class entrepreneurtab extends Fragment {
      //entdb e;
      Context context;
      int i=1;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          context=getActivity();
          View v = inflater.inflate(R.layout.entrepreneurtab, container, false);
          TableLayout table = (TableLayout) v.findViewById(R.id.TableLayout01);
         // e = new entdb(getActivity().getApplicationContext());
          Cursor c = ((entdb)getActivity()).getrec();
          c.moveToFirst();
          //add header
          TableRow tr = new TableRow(getContext());
          tr.setLayoutParams(getLayoutParams());
          tr.addView(getTextView(0, "COMPANY", Color.WHITE, Typeface.BOLD, Color.BLUE));
          tr.addView(getTextView(0, "OS", Color.WHITE, Typeface.BOLD, Color.BLUE));
          table.addView(tr, getTblLayoutParams());
          do {
              String u = c.getString(1);
              String comp = c.getString(3);
              String summ = c.getString(4);
              String dom = c.getString(5);
              tr.setLayoutParams(getLayoutParams());
              tr.addView(getTextView(1, u, Color.WHITE, Typeface.NORMAL, ContextCompat.getColor(getActivity(), R.color.colorAccent)));
              tr.addView(getTextView(1, comp, Color.WHITE, Typeface.NORMAL, ContextCompat.getColor(getActivity(), R.color.colorAccent)));
              tr.addView(getTextView(1, summ, Color.WHITE, Typeface.NORMAL, ContextCompat.getColor(getActivity(), R.color.colorAccent)));
              tr.addView(getTextView(1, dom, Color.WHITE, Typeface.NORMAL, ContextCompat.getColor(getActivity(), R.color.colorAccent)));
              table.addView(tr, getTblLayoutParams());
          } while (c.moveToNext());
          return v;
      }
  
  
      private LayoutParams getLayoutParams() {
          LayoutParams params = new LayoutParams(
                  LayoutParams.MATCH_PARENT,
                  LayoutParams.WRAP_CONTENT);
          params.setMargins(2, 0, 0, 2);
          return params;
      }
  
      private TableLayout.LayoutParams getTblLayoutParams() {
          return new TableLayout.LayoutParams(
                  LayoutParams.MATCH_PARENT,
                  LayoutParams.WRAP_CONTENT);
      }
  
      private TextView getTextView(int id, String title, int color, int typeface, int bgColor) {
          TextView tv = new TextView(getContext());
          tv.setId(id);
          tv.setText(title.toUpperCase());
          tv.setTextColor(color);
          tv.setPadding(40, 40, 40, 40);
          tv.setTypeface(Typeface.DEFAULT, typeface);
          tv.setBackgroundColor(bgColor);
          tv.setLayoutParams(getLayoutParams());
          return tv;
      }
  
  }
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>
  
  <p><strong>entdb.java</strong></p>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
  package com.example.swethaa.myapp;
  
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  import android.support.v7.app.AppCompatActivity;
  import android.widget.Toast;
  
  
  public class entdb extends AppCompatActivity {
      myDbHelper myhelper;
  
      public entdb(Context context) {
          myhelper = new myDbHelper(context);
      }
  
      public boolean insertData(String name, String pass, String comp, String summ, String Dom) {
          SQLiteDatabase dbb = myhelper.getWritableDatabase();
          ContentValues contentValues = new ContentValues();
          contentValues.put(myDbHelper.NAME, name);
          contentValues.put(myDbHelper.MyPASSWORD, pass);
          contentValues.put(myDbHelper.CompanyName, comp);
          contentValues.put(myDbHelper.Summary, summ);
          contentValues.put(myDbHelper.Domain, Dom);
          dbb.insert(myDbHelper.TABLE_NAME, null, contentValues);
           return  true;
      }
  
     public boolean check(String un, String pass)
     {
         SQLiteDatabase db =myhelper.getReadableDatabase();
         Cursor cursor= db.rawQuery("select * from "+ myDbHelper.TABLE_NAME,null);
         cursor.moveToFirst();
  
         do
         {
             String u = cursor.getString(1);
             String p = cursor.getString(2);
             if(u.equals(un) &amp;&amp; p.equals(pass))
             {
                 return true;
             }
         }while (cursor.moveToNext());
         return false;
  
  
  
     }
      public Cursor getrec()
      {
          SQLiteDatabase db =myhelper.getReadableDatabase();
          Cursor cursor= db.rawQuery("select * from "+ myDbHelper.TABLE_NAME,null);
          return  cursor;
      }
  
  
      public class myDbHelper extends SQLiteOpenHelper {
          private static final String DATABASE_NAME = "myDatabase";    // Database Name
          private static final String TABLE_NAME = "myTable";   // Table Name
          private static final int DATABASE_Version = 1;   // Database Version
          private static final String UID = "_id";     // Column I (Primary Key)
          private static final String NAME = "Name";    //Column II
          private static final String MyPASSWORD = "Password";    // Column III
          private static final String CompanyName = "company";
          private static final String Summary = "summary";
          private static final String Domain = "domain";
          private static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME +
                  " (" + UID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " VARCHAR(255) ," + MyPASSWORD + " VARCHAR(225), " + CompanyName + " VARCHAR(255) , " + Summary + " VARCHAR(255) , " + Domain + " VARCHAR(255) );";
          private Context context;
  
          public myDbHelper(Context context) {
              super(context, DATABASE_NAME, null, DATABASE_Version);
              this.context = context;
          }
  
          public void onCreate(SQLiteDatabase db) {
  
  
              db.execSQL(CREATE_TABLE);
  
          }
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                  db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
                  onCreate(db);
  
          }
  
  
              }
          }
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>
  
  <p><strong>entrepreneurtab.xml</strong></p>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none"&gt;
      &lt;TableLayout
          android:id="@+id/TableLayout01"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:stretchColumns="0"/&gt;
  &lt;/ScrollView&gt;
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>