大家好,我想使this LazyList动态化.我首先尝试过使用图像,但是用力将其关闭.如果我的方法错误,请指导.
这是代码
public class Test extends Activity { ListVIEw List; LazyAdapter adapter; private String[] mStrings; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); ArrayList<String> ListItems = new ArrayList<String>(); try { URL twitter = new URL( "http://mIDsweden.gofreeserve.com/proj/androIDJson.PHP?IDentifIEr=123"); URLConnection tc = twitter.openConnection(); BufferedReader in = new BufferedReader(new inputStreamReader( tc.getinputStream())); String line; while ((line = in.readline()) != null) { JsONArray ja = new JsONArray(line); for (int i = 0; i < ja.length(); i++) { JsONObject jo = (JsONObject) ja.get(i); ListItems.add(jo.getString("http://mIDsweden.gofreeserve.com/proj/admin/pictures/file87619.jpg")); } } } catch (MalformedURLException e) { // Todo auto-generated catch block e.printstacktrace(); } catch (IOException e) { // Todo auto-generated catch block e.printstacktrace(); } catch (JsONException e) { // Todo auto-generated catch block e.printstacktrace(); } mStrings = ListItems.toArray(new String[ListItems.size()]); List=(ListVIEw)findVIEwByID(R.ID.List); adapter=new LazyAdapter(this, mStrings); List.setAdapter(adapter); button b=(button)findVIEwByID(R.ID.button1); b.setonClickListener(Listener); } @OverrIDe public voID onDestroy() { adapter.imageLoader.stopThread(); List.setAdapter(null); super.onDestroy(); } public OnClickListener Listener=new OnClickListener(){ public voID onClick(VIEw arg0) { adapter.imageLoader.clearCache(); adapter.notifyDataSetChanged(); } };}
logcat的
07-09 01:00:51.825: WARN/dalvikvm(12674): threadID=3: thread exiting with uncaught exception (group=0x4001e390)07-09 01:00:51.835: ERROR/AndroIDRuntime(12674): Uncaught handler: thread main exiting due to uncaught exception07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.droIDnova.androID.howto.optionmenu/com.droIDnova.androID.howto.optionmenu.Test}: java.lang.NullPointerException07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2596)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.ActivityThread.access00(ActivityThread.java:126)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.os.Handler.dispatchMessage(Handler.java:99)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.os.Looper.loop(Looper.java:123)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.ActivityThread.main(ActivityThread.java:4595)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at java.lang.reflect.Method.invokeNative(Native Method)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at java.lang.reflect.Method.invoke(Method.java:521)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:618)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at dalvik.system.NativeStart.main(Native Method)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): Caused by: java.lang.NullPointerException07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at com.droIDnova.androID.howto.optionmenu.LazyAdapter.getCount(LazyAdapter.java:27)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.Widget.ListVIEw.setAdapter(ListVIEw.java:431)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at com.droIDnova.androID.howto.optionmenu.Test.onCreate(Test.java:35)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2544)07-09 01:00:51.865: ERROR/AndroIDRuntime(12674): ... 11 more07-09 01:00:51.895: INFO/Process(82): Sending signal. PID: 12674 SIG: 307-09 01:00:51.895: INFO/dalvikvm(12674): threadID=7: reacting to signal 3
解决方法:
您的NullPointer异常在getCount()第27行中:
Caused by: java.lang.NullPointerExceptionat com.droIDnova.androID.howto.optionmenu.LazyAdapter.getCount(LazyAdapter.java:27)
您可以通过将getCount()更改为以下内容来修复症状:
public int getCount() { if(data != null){ return data.length; } return 0;}
总结 以上是内存溢出为你收集整理的android-动态的惰性列表全部内容,希望文章能够帮你解决android-动态的惰性列表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)