Error while editing through SQLITE

Asked

Viewed 33 times

0

I’m trying to edit information that’s saved in the SQLITE gang. I’m working with fragments. But I’m making the following mistake:

FATAL EXCEPTION: main
                                                                                           Process: com.example.gerdaumanagement.gerdaumanagement, PID: 11997
                                                                                           android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.gerdaumanagement.gerdaumanagement/com.example.gerdaumanagement.gerdaumanagement.adicionar_usuario}; 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.gerdaumanagement.gerdaumanagement.usuario$UsuarioAdapter$2.onClick(usuario.java:218)
                                                                                               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)

I have a listview with all contacts, and in each contact I have an icon to edit and delete. The edit would be as follows:`

ImageView editarBt = (ImageView) view.findViewById(R.id.editar);
            editarBt.setOnClickListener(new Button.OnClickListener(){
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(getActivity(), adicionar_usuario.class);
                    intent.putExtra("nome", listaUser.get(auxPosition).getNome());
                    intent.putExtra("email", listaUser.get(auxPosition).getEmail());
                    intent.putExtra("np", listaUser.get(auxPosition).getNp());
                    intent.putExtra("tipoFunc", listaUser.get(auxPosition).getTipoFunc());
                    intent.putExtra("id", listaUser.get(auxPosition).getId());
                   getActivity().startActivity(intent);
                }
            });

When I click edit error happens.

I tried to change these codes:`

 ImageView editarBt = (ImageView) view.findViewById(R.id.editar);
            editarBt.setOnClickListener(new Button.OnClickListener(){
                @Override
                public void onClick(View view) {

                    Bundle data = new Bundle();
                    data.putString("nome", listaUser.get(auxPosition).getNome());
                    data.putString("email", listaUser.get(auxPosition).getEmail());
                    data.putString("np", listaUser.get(auxPosition).getNp());
                    data.putString("tipoFunc", listaUser.get(auxPosition).getTipoFunc());
                    data.putInt("id", listaUser.get(auxPosition).getId());
                    Fragment fragment = new adicionar_usuario();
                    fragment.setArguments(data);




                }
            });
`

Can anyone tell me the reason for this mistake?

  • You have a class called adicionar_usuario? It is not declared on Androidmanifest.xml

  • She’s a Fragment, so she’s not in the manifest. @Leonardodias

  • 2

    I believe this is the problem so, you can not do an Intent for a Fragment, you have to use the Fragmentmanager and change the Framelayout with the desired Fragment

  • @Leonardodias would you have an example of this? please?

  • I put the example code in the answer Lucas

1 answer

1


Lucas,

When you will put a Fragment in some Activity, you use the following code:

FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, adicionar_usuario, "adicionar usuário")
                .commit();

And in Layout, you should have a Framelayout with id container, example:

<FrameLayout
  android:id="@+id/container"
  android:layout_width="match_parent"
  android:layout_height="match_parent" />

You must have done it already to declare this current Fragment that you put the code there.

Any doubt screams there.

  • I edited my question with these tips.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.