0
votes

Oke so i'm really new to android studio and android app dev in general but i wanted to make a app that my youth movement could use as sort of a database but i ran into a problem.

So i have a drawer with all the groups and if you press the drawer buttons it opens a ListFragment with names and what i want to happen is when i press the name a activity shows up with the name a photo and a phone number. But i can't seem to figure out how to open a activity from that listFragment.

Here is the ListFragment.java

package app.jarifile.test;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
* Created by User on 23/09/2015.
*/
public class Givers_Fragment extends ListFragment {

Intent i;

String[] listitems = {
        "(Takleider)",
        "(Takleider)",
        "(Leider)",
        "(Leider)"
};
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, listitems));
}

@Override
public void onListItemClick(ListView l, View v, int position, long id){

    switch(position){
        case 0:
            i = new Intent(getActivity(), Test_Activity.class);
            break;
        case 1:
            i = new Intent(getActivity(), Test_Activity.class);
            break;
        case 2:
            i = new Intent(getActivity(), Test_Activity.class);
            break;
    }
    startActivity(i);
}

And this is the Test_Activity code.

package app.jarifile.test;

import android.app.Activity;
import android.os.Bundle;



/**
* Created by User on 24/09/2015.
*/

public class Test_Activity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_layout);
}

This is what logcat says

09-28 18:48:28.915 24081-24081/app.jarifile.test E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: app.jarifile.test, PID: 24081 android.content.ActivityNotFoundException: Unable to find explicit activity class {app.jarifile.test/app.jarifile.test.Test_Activity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1793) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515) at android.app.Activity.startActivityForResult(Activity.java:4026) at android.app.Activity.startActivityForResult(Activity.java:3973) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:748) at android.app.Activity.startActivity(Activity.java:4297) at android.app.Activity.startActivity(Activity.java:4265) at app.jarifile.test.Givers_Fragment.onListItemClick(Givers_Fragment.java:51) at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58) at android.widget.AdapterView.performItemClick(AdapterView.java:339) at android.widget.AbsListView.performItemClick(AbsListView.java:1544) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3721) at android.widget.AbsListView$3.run(AbsListView.java:5660) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6837) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 09-28 18:48:31.635 24081-24081/app.jarifile.test I/Process﹕ Sending signal. PID: 24081 SIG: 9

Thank you for the help.

2
What is happening when you select a list item? Nothing? Does your app crash?NasaGeek
The app crashes yes.Jari Flederick
Can you post the stack trace that gets produced when the app crashes? It should be available by inspecting the output of the adb log command or by looking at the "Android" window in Android Studio. Also, a potential cause of crashing is that you don't have a case for when you press the last item in the list (index 3). So you will try to call startActivity() with an uninitialized Intent.NasaGeek
I don't really get what you mean? I'm really really really new to this and coding in general and how would i find and post that?Jari Flederick
"Unable to find explicit activity class {app.jarifile.test/app.jarifile.test.Test_Activity}; have you declared this activity in your AndroidManifest.xml?"yiati

2 Answers

0
votes

You have not declared Test_Activity in your AndroidManifest.xml. All Activities in your app must be declared there. Here's an example of what that might look like:

 <manifest ... >
    <application ... >
      <activity android:name=".Test_Activity" />
      ...
    </application ... >
  ...
  </manifest>

http://developer.android.com/guide/components/activities.html#Declaring

0
votes

try to replace startActivity(i) with getActivity().startActivity(i)