Java.lang.NullPointerException in android.widget.ArrayAdapter.init (ArrayAdapter.java)

lang.NullPointerException android.widget.ArrayAdapter.init (ArrayAdapter.java) just add the Arraylist values ​​to the customAdapter class and set these values ​​in the listview see below helpm me code

thanks

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; } } 

when I run this code I get errors when deleting in 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 
+4
source share
1 answer

This problem is caused by the fact that getActivity () returns null when the adapter was created:

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

This can happen if the Activity is not already attached to the fragment or has been disconnected. To solve this problem, you can either make sure that the fetchCallLogsDetails method is called only in a valid state of attached activity. Or you can ignore the call if getActivity () == null or getActivity.isFinishing () .

+8
source

Source: https://habr.com/ru/post/1485058/


All Articles