0

I think the problem is the loading of the path and then the scaling of the image. The path is diredtedt to the MediaStore, but is saved as String in the db. Now I want to show a list with little thumbnails of this pichtures.

FATAL EXCEPTION: main java.lang.NullPointerException on the line onLoadFinished(Loader where the image is imChild.setImageBitmap(bmImg);

Here is the code:

    setListAdapter(adapter = new SimpleCursorAdapter(ChildrenActivity.this,
            R.layout.layout_list, null, new String[] {
            Children.COL_CHILD_IMAGE, Children.COL_CHILD_FIRSTNAME,Children.COL_CHILD_NUMBER }, new int[] {R.id.imagechild, R.id.textlist1,
            R.id.textlist2 }, 0));


    final ListView listView = getListView();

    // Load the content
    getLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {


            return new CursorLoader(ChildrenActivity.this,
                    YounikumProvider.URI_YOUNIKUM, Children.FIELDS, null, null,
                    null);
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor c) {


            if(c.getCount() == 0)
                return;
            String path = "";

            if(c.moveToFirst()) {
                path = c.getString(c.getColumnIndex("childImage"));
                File imgFile = new File(path);

                if(imgFile.exists()) {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inSampleSize = 2;

                    ImageView imChild = (ImageView) listView.findViewById(R.id.imagechild);
                    Bitmap bmImg = BitmapFactory.decodeFile(imgFile.getAbsolutePath(),options);


                  imChild.setImageBitmap(bmImg);
                }
            }


            ((SimpleCursorAdapter) getListAdapter()).swapCursor(c);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> arg0) {
            ((SimpleCursorAdapter) getListAdapter()).swapCursor(null);
        }
    });


        listView.setDivider(new ColorDrawable(Color.GRAY));
       listView.setDividerHeight(3); // 3 pixels height


    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {

        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
           getMenuInflater().inflate(R.menu.dailylog_context, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {


            if(item.getItemId() == R.id.dailylog_cab_delete) {

                //    SparseBooleanArray checkedDailyLogs = listView.getCheckedItemPositions();
                SparseBooleanArray checkedItems = listView.getCheckedItemPositions();

                final int checkedItemsCount = checkedItems.size();
                for(int i = 0; i < checkedItemsCount; i++) {

                    final int position = checkedItems.keyAt(i);
                    final boolean isChecked = checkedItems.valueAt(i);

                    int adid = (int) adapter.getItemId(position);

                    String selection =  listView.getItemAtPosition(position).toString();



                   Children childNo = DatabaseHandler.getInstance(ChildrenActivity.this).getChildren(adid);


                    if(checkedItems.valueAt(i)) {

                        ConnectivityManager connMgr = (ConnectivityManager)
                                getSystemService(Context.CONNECTIVITY_SERVICE);
                        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
                        if (networkInfo != null && networkInfo.isConnected()) {

                            //delete hier von Eintrag noch einfügen
                            DatabaseHandler.getInstance(ChildrenActivity.this).removeChildren(adid);
                           webdelete(Long.toString(childNo.child_number));


                            checkedItems = listView.getCheckedItemPositions();
                        }
                    }
                }
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {

        }
    });


    Button clickButton = (Button) findViewById(R.id.buttonAddChildren);
    clickButton.setOnClickListener( new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent childrenAddIntent = new Intent(ChildrenActivity.this, ChildrenAddActivity.class);
            startActivity(childrenAddIntent);
        }
    });
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • If the app is crashing then post the logcat output and tell us which line is causing the crash (which you can find in the logcat output). – takendarkk Nov 29 '14 at 23:21
  • FATAL EXCEPTION: main java.lang.NullPointerException on the line onLaodFinished(Loader where the image is imChild.setImageBitmap(bmImg); –  Nov 29 '14 at 23:31
  • Now which line throws the NPE? – takendarkk Nov 29 '14 at 23:32
  • You might want to read [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) and [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) – takendarkk Nov 29 '14 at 23:41
  • Either the view `R.id.imagechild` doesn't exist or `BitmapFactory.decodeFile(imgFile.getAbsolutePath(),options)` isn't finding anything. Use print statements to figure out which. – takendarkk Nov 29 '14 at 23:49
  • The problem is `listView.findViewById(...)`. The `ImageView` is not directly in the list but its items. Google how to use `CursorAdapter` correctly. – Eugen Pechanec Nov 29 '14 at 23:56
  • Thanks a lot for your answers... I have find out...it is because of to big pictures.....the memory at the end....I saved now thumbnails and it works perfect..... –  Nov 30 '14 at 10:40

0 Answers0