gpt4 book ai didi

android - java.lang.NullPointerException 在 android.widget.ArrayAdapter.init(ArrayAdapter.java)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:05 29 4
gpt4 key购买 nike

lang.NullPointerException android.widget.ArrayAdapter.init(ArrayAdapter.java)只是将 Arraylist 值添加到 customAdapter 类中并将该值设置到 ListView 中看下面的代码帮助我

谢谢

private void fetchCallLogsDetails(String selectedId) {
this.SelectedLogId = selectedId;
new FetchCallLogDetailsAsyncTask() {
protected void onPostExecute(Boolean result) {

if (mCallLogModel.getmPhoto() != null) {
mCallLogPhoto.setImageBitmap(mCallLogModel.getmPhoto());
}

mCallLogDetailName.setText(mCallLogModel.getmName());
mCallLogDetailNumber.setText(mCallLogModel.getmNumber());

mCallLogDetailName.setTextSize(12);
mCallLogDetailNumber.setTextSize(10);

mLogAuditUtilList = mCallLogModel.getmLogAuditUtilList();
if (mLogAuditUtilList != null) {
mCallLogAuditArrayAdapter = new CallLogAuditArrayAdapter(
getActivity(), R.id.details_audit_log_list,
mLogAuditUtilList);

mAuditListView.setAdapter(mCallLogAuditArrayAdapter);
}

};
}.execute("");
}
class FetchCallLogDetailsAsyncTask extends
AsyncTask<String, Integer, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
// reading call logs from contentReslover
mCallLogUtil = CallLogUtil.newInstance(mconContentResolver);
mCallLogModel = mCallLogUtil.selectedLogDetails(SelectedLogId);
return false;
}

}



customeAdapter class
-------------------------

public class CallLogAuditArrayAdapter extends ArrayAdapter<LogAuditUtil> {
private LayoutInflater minflater;
private ImageView mCallTypeImage;

public CallLogAuditArrayAdapter(Context context, int textViewResourceId,
List<LogAuditUtil> objects) {
super(context, textViewResourceId, objects);

minflater = LayoutInflater.from(context);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final LogAuditUtil mLogAuditUtil = this.getItem(position);

convertView = minflater.inflate(R.layout.call_logs_details_list_view,
null);
TextView mCallType = (TextView) convertView
.findViewById(R.id.call_logs_details_list_view_type_id);
TextView mDetailsDate = (TextView) convertView
.findViewById(R.id.call_logs_details_list_view_date_id);
mCallTypeImage = (ImageView) convertView
.findViewById(R.id.call_logs_details_list_view_type_image_id);

TextView mCallDuration = (TextView) convertView
.findViewById(R.id.call_logs_details_list_view_call_duration_id);

mCallType.setTextSize(12);
mDetailsDate.setTextSize(10);
mCallDuration.setTextSize(8);

switch (Integer.parseInt(mLogAuditUtil.getmAuditType())) {
case 1:
mCallType.setText(R.string.text_incoming_call);
mCallTypeImage.setImageResource(R.drawable.incoming_call);
break;

case 2:
mCallTypeImage.setImageResource(R.drawable.outgoing_call);
mCallType.setText(R.string.text_outgoing_call);
break;

case 3:
mCallTypeImage.setImageResource(R.drawable.missed_call);
mCallType.setText(R.string.text_missed_call);
break;
}

mDetailsDate.setText(mLogAuditUtil.getmAuditDate());
mCallDuration.setText(mLogAuditUtil.getmAuditDuration());
return convertView;
}

}

当我运行这段代码时,catlog 中出现错误

E/AndroidRuntime(3047): FATAL EXCEPTION: main
06-07 19:58:56.257: E/AndroidRuntime(3047): java.lang.NullPointerException
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
06-07 19:58:56.257: E/AndroidRuntime(3047): at com.movirtu.contactsUtil.CallLogsArrayAdapter.<init>(CallLogsArrayAdapter.java:30)
06-07 19:58:56.257: E/AndroidRuntime(3047): at com.movirtu.fragments.CallLogsFragment$2.onPostExecute(CallLogsFragment.java:88)
06-07 19:58:56.257: E/AndroidRuntime(3047): at com.movirtu.fragments.CallLogsFragment$2.onPostExecute(CallLogsFragment.java:1)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.os.AsyncTask.finish(AsyncTask.java:602)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.os.AsyncTask.access$600(AsyncTask.java:156)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.os.Looper.loop(Looper.java:137)
06-07 19:58:56.257: E/AndroidRuntime(3047): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-07 19:58:56.257: E/AndroidRuntime(3047): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 19:58:56.257: E/AndroidRuntime(3047): at java.lang.reflect.Method.invoke(Method.java:511)
06-07 19:58:56.257: E/AndroidRuntime(3047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-07 19:58:56.257: E/AndroidRuntime(3047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-07 19:58:56.257: E/AndroidRuntime(3047): at dalvik.system.NativeStart.main(Native Method)
06-07 19:58:58.917: I/Process(3047): Sending signal. PID: 3047 SIG: 9

最佳答案

此问题是由于在您创建适配器时 getActivity() 返回 null 造成的:

 new CallLogAuditArrayAdapter(getActivity(), R.id.details_audit_log_list, mLogAuditUtilList);

如果 Activity 尚未附加到 fragment ,或者它已分离,则可能会发生这种情况。要解决它,您可以确保方法 fetchCallLogsDetails 仅在附加 Activity 的有效状态下被调用,或者如果 getActivity() == null 或 < strong>getActivity.isFinishing().

关于android - java.lang.NullPointerException 在 android.widget.ArrayAdapter.init(ArrayAdapter.java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16986954/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com