I have 4 buttons on a screen, each one throws a different Activity but only one works for me

0

I am programming an app for a project, I have a screen with 4 buttons (menu) each button sends me to a new Activity but only the button that sends me to the profile activity works.

package com.example.slash.serviceconect;

import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button;

/ **  * Created by slash on 2/25/2018.  * /

public class menuduenoActivity extends AppCompatActivity implements View.OnClickListener {

Button eventos, irstock, empleados, perfil;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menudueno);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    perfil = (Button) findViewById(R.id.perfil);
    perfil.setOnClickListener(this);
    irstock = (Button) findViewById(R.id.botstock);
    irstock.setOnClickListener(this);
    eventos = (Button) findViewById(R.id.botevento);
    eventos.setOnClickListener(this);
    empleados = (Button) findViewById(R.id.botempleado);
    empleados.setOnClickListener(this);
}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.perfil:
            Intent intent = new Intent(this, perfilActivity.class);
            startActivity(intent);
            break;
        case R.id.botstock:
            Intent intent1 = new Intent(this, stockActivity.class);
            startActivity(intent1);
            break;
        case R.id.botevento:
            Intent intent2 = new Intent(this, eventosActivity.class);
            startActivity(intent2);
            break;
        case R.id.botempleado:
            Intent intent3 = new Intent(this, empleadosActivity.class);
            startActivity(intent3);
            break;
        default:
            break;
    }

}

}

This is the message from the console:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.slash.serviceconect, PID: 7477
              android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.slash.serviceconect/com.example.slash.serviceconect.stockActivity}; have you declared this activity in your AndroidManifest.xml?
                  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1895)
                  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1589)
                  at android.app.Activity.startActivityForResult(Activity.java:4229)
                  at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
                  at android.app.Activity.startActivityForResult(Activity.java:4187)
                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
                  at android.app.Activity.startActivity(Activity.java:4530)
                  at android.app.Activity.startActivity(Activity.java:4498)
                  at com.example.slash.serviceconect.menuduenoActivity.onClick(menuduenoActivity.java:81)
                  at android.view.View.performClick(View.java:5640)
                  at android.view.View$PerformClick.run(View.java:22455)
                  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:6165)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

The truth is that I need a solution because this error does not let me continue with my project, I have tried programming different ways to move between activities.

    
asked by Emmanuel Altamirano 30.03.2018 в 05:19
source

2 answers

1

Good evening Emmanuel,

The error that is indicated indicates that you can not find the Activity defined in your code, so I recommend that you look in your AndroidManifest.XML file if those activities are detailed.

If they do exist, you could see that the tags are inside the parent APPLICATION tag.

Example:

    <application
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"
       android:theme="@android:style/Theme.Light.NoTitleBar" >

       <activity  
          android:name=".Compte"  
          android:screenOrientation="portrait" />

       <activity
             android:name=".Menu" 
             android:screenOrientation="portrait"
             android:label="@string/app_name" >

             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>

       </activity>

    </application>
    
answered by 30.03.2018 в 06:19
-1

In this case the error message is:

  

Process: com.example.slash.serviceconect, PID: 7477                 android.content.ActivityNotFoundException: Unable to find explicit activity class   {com.example.slash.serviceconect / com.example.slash.serviceconect.stockActivity};   have you declared this activity in your AndroidManifest.xml?

That translating it into Spanish would be:

  

Process: com.example.slash.serviceconect, PID: 7477   android.content.ActivityNotFoundException: you can not find the explicit activity class   {com.example.slash.serviceconect / com.example.slash.serviceconect.stockActivity};    Did you declare this activity on your AndroidManifest.xml?

All the Activity that are used in your project must be declared within your file AndroidManifest.xml , within <application> :

 ...
 ...
       <activity android:name=".perfilActivity"/>
       <activity android:name=".stockActivity"/>
       <activity android:name=".eventosActivity"/>
       <activity android:name=".empleadosActivity"/>

    </application>
</manifest>
    
answered by 31.03.2018 в 01:38