我有一个ListView
我正在从SQLite数据库中填充。我的HTC Hero 2.1上的ListView
中有350行,一切正常。我在三星Galaxy S 2.2上安装了它,我的ListView
中有270行,每当我到达ListView
滚动列表的底部附近时,我的应用程序崩溃了。
这是日志文件:
06-17 14:29:33.796 W/dalvikvm( 3565): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
06-17 14:29:33.816 E/AndroidRuntime( 3565): FATAL EXCEPTION: main
06-17 14:29:33.816 E/AndroidRuntime( 3565): java.lang.NullPointerException
06-17 14:29:33.816 E/AndroidRuntime( 3565): at aec.phonebook.ListContacts$ItemAdapter.getView(ListContacts.java:539)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.AbsListView.obtainView(AbsListView.java:1410)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.ListView.makeAndAddView(ListView.java:1802)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.ListView.fillDown(ListView.java:727)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.ListView.fillGap(ListView.java:698)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3367)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2251)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.widget.ListView.onTouchEvent(ListView.java:3605)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.View.dispatchTouchEvent(View.java:3819)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1723)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1129)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1707)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.view.ViewRoot.handleMessage(ViewRoot.java:1810)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.os.Handler.dispatchMessage(Handler.java:99)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.os.Looper.loop(Looper.java:123)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at java.lang.reflect.Method.invokeNative(Native Method)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at java.lang.reflect.Method.invoke(Method.java:521)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-17 14:29:33.816 E/AndroidRuntime( 3565): at dalvik.system.NativeStart.main(Native Method)
06-17 14:29:33.827 W/ActivityManager( 2465): Force finishing activity aec.phonebook/.ListContacts
06-17 14:29:33.831 I/ ( 2465): dumpmesg > "/data/log/dumpstate_app_error.log"
06-17 14:29:33.855 I/dumpstate( 3830): begin
06-17 14:29:33.890 V/InputDevice( 2465): ID[0]=0(0) Up(1=>0)
06-17 14:29:36.890 W/PowerManagerService( 2465): Timer 0x7->0x3|0x0
06-17 14:29:36.890 I/PowerManagerService( 2465): Ulight 7->3|0
06-17 14:29:36.929 D/VoldCmdListener( 2348): asec list
06-17 14:29:36.937 D/VoldCmdListener( 2348): CommandListener::AsecCmd::runCommand -> com.fridgecat.android.atiltlite-1
06-17 14:29:38.222 I/dumpstate( 3830): done
06-17 14:29:38.370 W/WindowManager( 2465): No window to dispatch pointer action 1
06-17 14:29:38.374 W/ActivityManager( 2465): Activity pause timeout for HistoryRecord{4806e860 aec.phonebook/.ListContacts}
编辑:
以下是代码:
@Override
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Item j = items.get(position);
if (j != null) {
TextView tvn = (TextView)v.findViewById(R.id.textViewName);
TextView tvnum = (TextView)v.findViewById(R.id.textViewNumber);
TextView tvid = (TextView)v.findViewById(R.id.textViewId);
TextView tvoper = (TextView)v.findViewById(R.id.textViewOperator);
if (tvn != null) {
tvn.setText(j.getname());
}
if(tvnum != null){
tvnum.setText(j.getnumber());
}
if (tvid != null) {
tvid.setText(j.getid());
}
if(tvoper != null){
tvoper.setText(j.getoperator());
if(j.getstatus().equals("0")){
tvoper.setTextColor(Color.WHITE);
}
if(j.getstatus().equals("1")){
tvoper.setTextColor(Color.GREEN);
}
if(j.getstatus().equals("2")){
tvoper.setTextColor(Color.RED);
}
}
}
}
答案 0 :(得分:1)
您的代码中可能出现的错误可能是您定义的“字符串数组大小”。
例如:您创建的StringArray有270个元素,但您定义的大小可能超过270个。 这会在剩余的未初始化数组中产生空值的问题。
因此,请确保ArraySize等于ListSize ..
希望有所帮助