Los servicios del sistema no están disponibles para actividades antes de onCreate () con Fragment y ListActivity

Hi I am receiving the following error: System services not available to Activities before onCreate()

I understand this is a common error and from debugging I found the error is in my Activity file (adapter = new RssListAdapter(this,jobs);//where error is occuring). I just do not know what the workaround is. Here is the following code:

My newspaper file:

public class NewspaperFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    List<JSONObject> testing = new ArrayList<JSONObject>();
    final RssActivity activity1 = new RssActivity();
    (new Thread(new Runnable() {

        public void run() {



    activity1.test();

        }
    })).start();

    return inflater.inflate(R.layout.newspaper_fragment, container, false);
}
}

And here is the Activity class I am calling which is extending a ListActivity

public class RssActivity extends ListActivity {

private RssListAdapter adapter;

/** Called when the activity is first created. */
public void test() {

    //super.onCreate(savedInstanceState);
    List<JSONObject> jobs = new ArrayList<JSONObject>();
    try {


        jobs = RssReader.getLatestRssFeed();


        //setListAdapter(adapter);

    } catch (Exception e) {
        Log.e("RSS ERROR", "Error loading RSS Feed Stream >> " + e.getMessage() + " //" + e.toString());
    }
    adapter = new RssListAdapter(this,jobs);//where error is occuring

}

}

I have been working on this problem for a few days but keep getting stuck on this area.

preguntado el 09 de marzo de 12 a las 23:03

1 Respuestas

Estás intentando crear un RssActivity a través de su constructor. NEVER DO THIS.

As a result, you are calling test() on an activity that has not gone through the normal lifecycle, notably not having been called by the system with onCreate().

respondido 10 mar '12, 00:03

So how should I handle this? I am trying to use the ListActivity through the RssListAdapter class but at the same time my newspaperfragment file needs to extend the fragment class because it is part of something else. Thanks - Letheone1

@user977205: To be blunt, you probably start over. It feels like you are randomly attaching things, hoping to get something to work, rather than taking the time to build up your skills from simpler projects or structured resources. - CommonsWare

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.