Error in the Adapterview

Asked

Viewed 71 times

5

Good evening, I am trying to call an activty by an Adapter through Intent, but gives the following error:

FATAL EXCEPTION: main Process: com.compscitutorials.basigarcia.navigationdrawervideotutorial, PID: 20374 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.compscitutorials.basigarcia.navigationdrawervideotutorial/br.com.projeto.caminhossembarreiras.activity.Activity_Acess}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1885) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1697) at android.app.Activity.startActivityForResult(Activity.java:4557) at android.app.Activity.startActivityFromFragment(Activity.java:4543) at android.app.Activity$Hostcallbacks.onStartActivityFromFragment(Activity.java:6623) at android.app.Fragment.startActivity(Fragment.java:1092) at android.app.Fragment.startActivity(Fragment.java:1071) at br.com.projeto.caminhossembarreiras.Acessfragment.onItemClick(Acessfragment.java:39) at android.widget.Adapterview.performItemClick(Adapterview.java:310) at android.widget.Abslistview.performItemClick(Abslistview.java:1145) at android.widget.Abslistview$Performclick.run(Abslistview.java:3049) at android.widget.Abslistview$3.run(Abslistview.java:3886) at android.os.Handler.handleCallback(Handler.java:746) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.Activitythread.main(Activitythread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:728) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:618)

Fragment of the Adapter:

public class AcessFragment extends Fragment implements AdapterView.OnItemClickListener {
private ListView lista;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_acess, container, false);

    lista = (ListView) rootView.findViewById(R.id.lista);
    lista.setAdapter(new AdapterAcess(getContext()));
    lista.setOnItemClickListener(this);

    return rootView;
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int idx , long id) {

    if (idx == 0) {
        Intent it = new Intent(getContext(), Activity_Acess.class);
        startActivity(it);
    } else if (idx == 1) {

    } else if (idx == 2) {

    } else if (idx == 3) {

    } else if (idx == 4) {

    }

}

XML:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView
    android:id="@+id/lista"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#ececec"
    android:padding="10dp"
    android:dividerHeight="2sp"
    />

Adapter:

public class AdapterAcess extends BaseAdapter {

private String[] itens = new String[]{"Acessibilidade", "Seus Direitos", "Outros"};
private Context context;

public AdapterAcess(Context context){
    super();
    this.context = context; // O context é necessario para criar a view.
}

@Override

public int getCount() {
    return itens.length; // Retorna a quantida de itens do adapter.
}

@Override
public Object getItem(int position) {
    return itens[position]; // Retorna o objeto para esta posição.
}

@Override
public long getItemId(int position) {
    return position; // Retorna o id do obejto para esta posição;
}

@Override
// Retorna o view para esta posição.
public View getView(int position, View convertView, ViewGroup parent) {


    String lista = itens[position];
    TextView t = new TextView(context);
    float dip = 50;
    float densidade = context.getResources().getDisplayMetrics().density; // Densidade da tela.

    int px = (int) (dip * densidade + 0.5f);
    t.setHeight(px);
    t.setText(lista);
    return t;

}

}

  • 1

    right here: "have you declared this Activity in your Androidmanifest.xml?" , you probably did not declare your Activity in the manifest file, all activities you will be using should be declared there if you want to know how to do this: http://developer.android.com/intl/pt-br/guide/topics/manifest/activity-element.html, if you search in google will char some more direct and simple tutorials

  • Thanks, good to know it. I’m starting now on android!

1 answer

6


Any Activity you will call, either through: Intent, buttons, side scroll etc, must be declared in the manifest. I created a new project to better illustrate.

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ajuda.ajuda.ajuda">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
        android:name=".NEW_ACTIVITY"
        android:configChanges="orientation"
        android:screenOrientation="portrait">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Note that within the TAG application, I added a new Activity called: NEW_ACTIVITY if it is not stated here, when calling it through another Activity, the app will "crash".

Any doubt, look at this video https://www.youtube.com/watch?v=3zGoM5VIQh8 helped me a lot when I started, and it’s still in Portuguese.

  • Thank you, I’m sure you’ll help me a lot!

Browser other questions tagged

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