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;
}
}
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
– ProgramandoMil
Thanks, good to know it. I’m starting now on android!
– Lari Souza