0

I am trying to refresh my custom ListViewAdapter;

Edit :

When I click an item in Listview it is calling the GoruntuleActivity's screen and creating oncreate method (I am assuming it is creating..) and then I call a method of GoruntuleActivity and the layputInflater is into this Activity.

ListeleActivity.java

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View item,
                    int position, long id) {

                onClickPosition = position;

                final Intent intent = new Intent(ListeleActivity.this,
                        GoruntuleActivity.class);
                startActivity(intent);

                goruntuleNesnesi.isSetListRefresh(onClickPosition , issetlist);
            }
        });

and it is calling the method of GoruntuleActivity.java

  public void isSetListRefresh(int onClickPosition, ArrayList<String> issetlist )
    {
        issetlist.set(onClickPosition, "false");
        setRecentOrSeen(issetlist);
        ListviewRefresh();
    }

    public void ListviewRefresh() 
    {
        LayoutInflater mLInflater = LayoutInflater.from(this);

        ListViewAdapter adapter = new ListViewAdapter(
                getApplicationContext(), getKimdenList(), getKonuList(), getRecentOrSeen() ,
                mLInflater);
        adapter.Remove();

    }

And now it is giving me another Exception..

05-18 16:25:22.073: E/AndroidRuntime(807): FATAL EXCEPTION: main
05-18 16:25:22.073: E/AndroidRuntime(807): java.lang.IllegalStateException: System services not available to Activities before onCreate()
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.app.Activity.getSystemService(Activity.java:3526)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.view.LayoutInflater.from(LayoutInflater.java:171)
05-18 16:25:22.073: E/AndroidRuntime(807):  at com.mobil.eposta.GoruntuleActivity.ListviewRefresh(GoruntuleActivity.java:160)
05-18 16:25:22.073: E/AndroidRuntime(807):  at com.mobil.eposta.GoruntuleActivity.isSetListRefresh(GoruntuleActivity.java:155)
05-18 16:25:22.073: E/AndroidRuntime(807):  at com.mobil.eposta.ListeleActivity$1.onItemClick(ListeleActivity.java:137)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.widget.ListView.performItemClick(ListView.java:3382)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.os.Handler.handleCallback(Handler.java:587)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.os.Looper.loop(Looper.java:123)
05-18 16:25:22.073: E/AndroidRuntime(807):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-18 16:25:22.073: E/AndroidRuntime(807):  at java.lang.reflect.Method.invokeNative(Native Method)
05-18 16:25:22.073: E/AndroidRuntime(807):  at java.lang.reflect.Method.invoke(Method.java:521)
05-18 16:25:22.073: E/AndroidRuntime(807):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-18 16:25:22.073: E/AndroidRuntime(807):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-18 16:25:22.073: E/AndroidRuntime(807):  at dalvik.system.NativeStart.main(Native Method)
Merve Gül
  • 1,377
  • 6
  • 23
  • 40

1 Answers1

2

From the error logs, it looks like getApplicationContext() is returning null. When are you calling goruntuleNesnesi.ListviewRefresh();? Is it in the onCreate(...)? If so, that may be your problem as getApplicationContext(...) will return null until onCreate(...) is done initializing.

Edit: I looked through the stack trace a bit more and it looks like you're calling ListviewRefresh on a button click. Have you tried using this instead of getApplicationContext(...)?

Edit 2: Try this:

ListViewAdapter adapter = new ListViewAdapter(this, getKimdenList(), getKonuList(), getRecentOrSeen() ,mLInflater); 

Although, I think it may suffer from the same problem because the activity hasn't been drawn on the screen yet and hasn't been initialized, you can't inflate views on it. Try it out and we'll go from there.

Gophermofur
  • 2,101
  • 1
  • 14
  • 14
  • You are right! I am calling layoutinflater before oncrete is not created. And I try call the layputinflater after goruntuleactivity's oncreate but it is gave me a "real error". I mean before your comment my application giving exception with orange color and didnt crash but after oncreate and layoutinflater calling it is crash:S What should I do? I edit my new Logcat error in my question – Merve Gül May 18 '12 at 16:18
  • I tried this and the result is make me confused:S I will edit all my code with simple mode to explain my code.... – Merve Gül May 18 '12 at 16:27
  • Sorry, I should have been more clear. I mean when creating the adapter, try using `this`. See my edited answer. – Gophermofur May 18 '12 at 16:40
  • I change my code like you said for oncreate method, and the excepiton is gone Thank you so much! – Merve Gül May 18 '12 at 16:44