Sziasztok,
hosszas keresés után ide jutottam...
A következő a problémám:
Van kettő listView-em. Egyik a main.xml layout-on, a másik pedig egy másikon (waitlay.xml). A main.xml-en lévőt sikeresen feltudom tölteni, de ha átváltok a másik layoutra, akkor az azon lévő listView feltöltését akarom elvégezni egy tömbből, megáll a program.
Köszönöm a választ!
A kód részlet:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BupoActivity.context = getApplicationContext(); listView = (ListView) findViewById(R.id.mylist); listView2 = (ListView) findViewById(R.id.mylist2); database = new megallok(this); create_list2(); } public void create_list(){ String[] values = new String[] { "Android", "iPhone", "WindowsMobile","Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X","Linux", "OS/2" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_list_item_2, android.R.id.text2, values); listView.setAdapter(adapter); } public void create_list2(){ String[] values = new String[] { "Android", "iPhone", "WindowsMobile","Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X","Linux", "OS/2" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_list_item_2, android.R.id.text2, values); listView2.setAdapter(adapter); } public void click(View view) { switch (view.getId()) { case R.id.wait: setContentView(R.layout.waitlay); //ITT SZÁLL EL. create_list(); Toast.makeText(this, "Wait",Toast.LENGTH_LONG).show(); create_list(); break; case R.id.move: Toast.makeText(this, "Move",Toast.LENGTH_LONG).show(); break; } }
Logcat:
07-16 08:11:13.304: W/dalvikvm(283): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-16 08:11:13.499: E/AndroidRuntime(283): FATAL EXCEPTION: main
07-16 08:11:13.499: E/AndroidRuntime(283): java.lang.IllegalStateException: Could not execute method of the activity
07-16 08:11:13.499: E/AndroidRuntime(283): at android.view.View$1.onClick(View.java:2072)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.view.View.performClick(View.java:2408)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.view.View$PerformClick.run(View.java:8816)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.os.Handler.handleCallback(Handler.java:587)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.os.Handler.dispatchMessage(Handler.java:92)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.os.Looper.loop(Looper.java:123)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-16 08:11:13.499: E/AndroidRuntime(283): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 08:11:13.499: E/AndroidRuntime(283): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 08:11:13.499: E/AndroidRuntime(283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-16 08:11:13.499: E/AndroidRuntime(283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-16 08:11:13.499: E/AndroidRuntime(283): at dalvik.system.NativeStart.main(Native Method)
07-16 08:11:13.499: E/AndroidRuntime(283): Caused by: java.lang.reflect.InvocationTargetException
07-16 08:11:13.499: E/AndroidRuntime(283): at bupo.pack.com.BupoActivity.click(BupoActivity.java:57)
07-16 08:11:13.499: E/AndroidRuntime(283): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 08:11:13.499: E/AndroidRuntime(283): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 08:11:13.499: E/AndroidRuntime(283): at android.view.View$1.onClick(View.java:2067)
07-16 08:11:13.499: E/AndroidRuntime(283): ... 11 more
07-16 08:11:13.499: E/AndroidRuntime(283): Caused by: java.lang.NullPointerException
07-16 08:11:13.499: E/AndroidRuntime(283): at bupo.pack.com.BupoActivity.create_list(BupoActivity.java:45)
07-16 08:11:13.499: E/AndroidRuntime(283): ... 15 more
4 Comments
Auth Gábor
Szerintem ez a baj:
07-16 08:11:13.499: E/AndroidRuntime(283): Caused by: java.lang.NullPointerException
07-16 08:11:13.499: E/AndroidRuntime(283): at bupo.pack.com.BupoActivity.create_list(BupoActivity.java:45)
Milyen forrásrészlet van a BupoActivity.java fájlban a 45. sorban?
Roland Kruska
#43 String[] values = new String[] { "Android", "iPhone", "WindowsMobile","Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X","Linux", "OS/2" };
#44 ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_list_item_2, android.R.id.text2, values);
#45 listView.setAdapter(adapter);
Auth Gábor
Valószínűleg azért, mert beállítasz egy új View-t a getContentView hívással és a korábban beállított listView így üres lesz...
Roland Kruska
Zsír, megy.
végül is ezért az 1 sorért voltam fennt hajnalig tegnap(ma).
Köszönöm a fényt.
public void create_list(){
listView = (ListView) findViewById(R.id.mylist);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile","Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X","Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_list_item_2, android.R.id.text2, values);
listView.setAdapter(adapter);
}