move to a fragmet using a bottonbar

1

the problem is the next I have an activiy and in that activity I have a buttonBar , when I try to pass to fragment by clicking a buttonBar button gives me an error.

This is the code

    public class ElectricalCalculators extends AppCompatActivity  implements View.OnClickListener {


   Button kwbutton , evbutton ;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_electrical_calculators);



        findViewById(R.id.menu_back).setOnClickListener(this);
        findViewById(R.id.menu_home).setOnClickListener(this);


        Button kwbutton = (Button) findViewById(R.id.ampsBoutton);
        kwbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( v.getContext() , AmpsConversion.class);
                startActivityForResult(intent,0);
            }
        });


        Button evbutton = (Button) findViewById(R.id.evBoutton);
        evbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( v.getContext() , ElectronVoltsConversion.class);
                startActivityForResult(intent,0);
            }
        });


        Button jbutton = (Button) findViewById(R.id.joulesBoutton);
        jbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( v.getContext() , JoulesConversion.class);
                startActivityForResult(intent,0);
            }
        });


        Button Kwbutton = (Button) findViewById(R.id.kwBoutton);
        Kwbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( v.getContext() , KwConversion.class);
                startActivityForResult(intent,0);
            }
        });



        Button Kwhbutton = (Button) findViewById(R.id.kwhBoutton);
        Kwhbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( v.getContext() , KwhConversion.class);
                startActivityForResult(intent,0);
            }
        });




    }

    @Override
    public void onClick(View v) {


        Class clazz = null;

        FragmentManager fragmentManager = getSupportFragmentManager();



        if (v.getId() == R.id.menu_back){

           fragmentManager.beginTransaction().replace(R.id.elctricalCalculator,  new Fragmen2()).commit();



        }


       /** switch (v.getId()) {


            case R.id.menu_back:

                //clazz = Fragmen2.class;
                fragmentManager.beginTransaction().replace(R.id.elctricalCalculator,  new Fragmen2()).commit();


                break;

            case R.id.menu_home:
                clazz = MainActivity.class;
                break;
            /**case R.id.five_tabs_changing_colors:
             clazz = FiveColorChangingTabsActivity.class;
             break;*/

        //}


//        startActivity(new Intent(this, clazz));

    }
}

and the error is:

ATAL EXCEPTION: main


Process: com.example.liantonypozo.calculos, PID: 10048
                                                                                           android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.liantonypozo.calculosmatematicos3/com.example.liantonypozo.calculos.Fragmen2}; have you declared this activity in your AndroidManifest.xml?
                                                                                               at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
                                                                                               at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
                                                                                               at android.app.Activity.startActivityForResult(Activity.java:4225)
                                                                                               at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
                                                                                               at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
                                                                                               at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                                               at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
                                                                                               at android.app.Activity.startActivity(Activity.java:4522)
                                                                                               at android.app.Activity.startActivity(Activity.java:4490)
                                                                                               at com.example.liantonypozo.calculosmatematicos3.ElectricalCalculators.onClick(ElectricalCalculators.java:97)
                                                                                               at android.view.View.performClick(View.java:5637)
                                                                                               at android.view.View$PerformClick.run(View.java:22429)
                                                                                               at android.os.Handler.handleCallback(Handler.java:751)
                                                                                               at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                               at android.os.Looper.loop(Looper.java:154)
                                                                                               at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
    
asked by Liantony Pozo 21.05.2017 в 04:16
source

1 answer

0

Review the error, this indicates that it has not been registered in the AndroidManifest.xml the Activity Fragmen2 :

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.liantonypozo.calculosmatematicos3/com.example.liantonypozo.calculos.Fragmen2}; have you declared this activity in your AndroidManifest.xml?

add the activity within your AndroidManifest.xml to be registered in your application.

  <application
     ...
      ...
      <activity android:name=".Fragmen2"/>
  </application>

Is the name of the Activity is Fragment2 ? if in truth it is a Activity and extends from Activity or AppCompatActivity , it should open without problem when opening the Activity using startActivity() :

  clazz = Fragmen2.class;
  startActivity(new Intent(this, clazz));

If your class Fragmen2.class is a Fragment , you have to make a transaction.

Move from one fragment to another

    
answered by 22.05.2017 в 20:11