Error in AdapterView

5

Good night, I'm trying to call an activty by an adapter through intent, but it 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.project.paths.support.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.project.paths.projects.AcessFragment.onItemClick (AccessFragment.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)

Adapter Fragment:

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;

}

}

    
asked by anonymous 02.05.2016 / 00:21

1 answer

6

Any activity you call, whether through: intent, buttons, side scroll etc, should be declared in the manifest. I've created a new project to better exemplify.

    <?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>

Notice that within the TAG application, I added a new activity called: NEW_ACTIVITY if it is not declared here, when calling it through another activity, the app will crash.

>

Any doubt, watch this video helped me a lot when I started, and is still in Portuguese.

    
02.05.2016 / 03:18