Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:56:29+00:00 2026-05-24T15:56:29+00:00

I need to find a way to set ListView addapter to null.The reason I

  • 0

I need to find a way to set ListView addapter to null.The reason I want to do that is that I have 4 child activities in Tab and each one of these activities are lazy loading lists.In OnDestroy method of the activity I do this :

@Override
public void onDestroy()
{
    adapter.imageLoader.stopThread();
    listView.setAdapter(null);
    super.onDestroy();
}

But when I do this I get this exception :

08-13 15:29:43.115: ERROR/AndroidRuntime(10381): FATAL EXCEPTION: main
08-13 15:29:43.115: ERROR/AndroidRuntime(10381): java.lang.RuntimeException: Unable to destroy activity {com.stampii.stampii/com.stampii.stampii.mystampii.OwnedStampii}: java.lang.NullPointerException
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3874)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3784)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.LocalActivityManager.performDestroy(LocalActivityManager.java:355)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.LocalActivityManager.destroyActivity(LocalActivityManager.java:381)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at com.stampii.stampii.TabGroupActivity.finishFromChild(TabGroupActivity.java:46)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.Activity.finish(Activity.java:3290)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at com.stampii.stampii.mystampii.OwnedStampii$1.onClick(OwnedStampii.java:38)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.view.View.performClick(View.java:2408)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.view.View$PerformClick.run(View.java:8817)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.os.Handler.handleCallback(Handler.java:587)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.os.Looper.loop(Looper.java:144)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.ActivityThread.main(ActivityThread.java:4937)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at java.lang.reflect.Method.invoke(Method.java:521)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at dalvik.system.NativeStart.main(Native Method)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381): Caused by: java.lang.NullPointerException
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at com.stampii.stampii.mystampii.OwnedStampii.onDestroy(OwnedStampii.java:102)
08-13 15:29:43.115: ERROR/AndroidRuntime(10381):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3861)

at line 102 I have this : listView.setAdapter(null);

If I remove that code I get :

08-13 15:33:36.545: ERROR/AndroidRuntime(10511): FATAL EXCEPTION: main
08-13 15:33:36.545: ERROR/AndroidRuntime(10511): java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at java.util.Vector.elementAt(Vector.java:329)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at java.util.Vector.get(Vector.java:443)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at com.stampii.stampii.tableview.ImageLoader$PhotosQueue.Clean(ImageLoader.java:126)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at com.stampii.stampii.tableview.ImageLoader.queuePhoto(ImageLoader.java:59)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at com.stampii.stampii.tableview.ImageLoader.DisplayImage(ImageLoader.java:51)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at com.stampii.stampii.tableview.LazyAdapter.getView(LazyAdapter.java:62)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.AbsListView.obtainView(AbsListView.java:1294)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.ListView.onMeasure(ListView.java:1109)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:521)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.View.measure(View.java:8172)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewRoot.performTraversals(ViewRoot.java:805)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.os.Looper.loop(Looper.java:144)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at android.app.ActivityThread.main(ActivityThread.java:4937)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at java.lang.reflect.Method.invoke(Method.java:521)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-13 15:33:36.545: ERROR/AndroidRuntime(10511):     at dalvik.system.NativeStart.main(Native Method)

And here is ImageLoader.class :

package com.stampii.stampii.tableview;

import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Stack;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import com.stampii.stampii.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.widget.ImageView;

public class ImageLoader extends Activity {

    //the simplest in-memory cache implementation. This should be replaced with something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
    private HashMap<String, Bitmap> cache=new HashMap<String, Bitmap>();

    private File cacheDir;
    private AssetManager mAssetManager;


    public ImageLoader(Context context){
        //Make the background thead low priority. This way it will not affect the UI performance
        photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
        mAssetManager = context.getAssets();

        //Find the dir to save cached images
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
        else
            cacheDir=context.getCacheDir();
        if(!cacheDir.exists())
            cacheDir.mkdirs();
    }


    final int stub_id=R.drawable.default_img;
    public void DisplayImage(String url, Activity activity, ImageView imageView)
    {
        if(cache.containsKey(url))
            imageView.setImageBitmap(cache.get(url));
        else
        {
            queuePhoto(url, activity, imageView);
            imageView.setImageResource(stub_id);
        }    
    }

    private void queuePhoto(String url, Activity activity, ImageView imageView)
    {
        //This ImageView may be used for other images before. So there may be some old tasks in the queue. We need to discard them. 
        photosQueue.Clean(imageView);
        PhotoToLoad p=new PhotoToLoad(url, imageView);
        synchronized(photosQueue.photosToLoad){
            photosQueue.photosToLoad.push(p);
            photosQueue.photosToLoad.notifyAll();
        }

        //start thread if it's not started yet
        if(photoLoaderThread.getState()==Thread.State.NEW)
            photoLoaderThread.start();
    }

    private Bitmap getBitmap(String src) {
        Bitmap myBitmap = null;


                //Decryption
                try {
                Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
                SecretKeySpec keySpec = new SecretKeySpec("01234567890abcde".getBytes(), "AES");
                IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes());
                cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

                InputStream input = mAssetManager.open(src);
                CipherInputStream cis = new CipherInputStream(input, cipher);

                myBitmap = BitmapFactory.decodeStream(cis);

                }
                catch(Exception e){
                    e.printStackTrace();
                    Log.v("ERROR","Error : "+e);
                }


                return myBitmap;


        }

    //Task for the queue
    private class PhotoToLoad
    {
        public String url;
        public ImageView imageView;
        public PhotoToLoad(String u, ImageView i){
            url=u; 
            imageView=i;
        }
    }

    PhotosQueue photosQueue=new PhotosQueue();

    public void stopThread()
    {
        photoLoaderThread.interrupt();
    }

    //stores list of photos to download
    class PhotosQueue
    {
        private Stack<PhotoToLoad> photosToLoad=new Stack<PhotoToLoad>();

        //removes all instances of this ImageView
        public void Clean(ImageView image)
        {
            for(int j=0 ;j<photosToLoad.size();){
                if(photosToLoad.get(j).imageView==image)
                    photosToLoad.remove(j);
                else
                    ++j;
            }
        }
    }

    class PhotosLoader extends Thread {
        public void run() {
            try {
                while(true)
                {
                    //thread waits until there are any images to load in the queue
                    if(photosQueue.photosToLoad.size()==0)
                        synchronized(photosQueue.photosToLoad){
                            photosQueue.photosToLoad.wait();
                        }
                    if(photosQueue.photosToLoad.size()!=0)
                    {
                        PhotoToLoad photoToLoad;
                        synchronized(photosQueue.photosToLoad){
                            photoToLoad=photosQueue.photosToLoad.pop();
                        }
                        Bitmap bmp=getBitmap(photoToLoad.url);
                        cache.put(photoToLoad.url, bmp);
                        Object tag=photoToLoad.imageView.getTag();
                        if(tag!=null && ((String)tag).equals(photoToLoad.url)){
                            BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad.imageView);
                            Activity a=(Activity)photoToLoad.imageView.getContext();
                            a.runOnUiThread(bd);
                        }
                    }
                    if(Thread.interrupted())
                        break;
                }
            } catch (InterruptedException e) {
                //allow thread to exit
            }
        }
    }

    PhotosLoader photoLoaderThread=new PhotosLoader();

    //Used to display bitmap in the UI thread
    class BitmapDisplayer implements Runnable
    {
        Bitmap bitmap;
        ImageView imageView;
        public BitmapDisplayer(Bitmap b, ImageView i){bitmap=b;imageView=i;}
        public void run()
        {
            if(bitmap!=null)
                imageView.setImageBitmap(bitmap);
            else
                imageView.setImageResource(stub_id);
        }
    }

    public void clearCache() {
        //clear memory cache

        long size=0;
            cache.clear();

            //clear SD cache
            File[] files=cacheDir.listFiles();
            for(File f:files){
                size=size+f.length();
                    f.delete();
            }
}




}

Any ideas how to fix that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:56:29+00:00Added an answer on May 24, 2026 at 3:56 pm

    You assign null as the adapter. Thats not a valid one and will of course throw a NullPointerException to emphasize this.

    The other exception is hard to tell with that small piece of code. Please post some more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find some way of displaying a drop-down menu that depending on
I need to find a way to have the multiple choice options in a
I need to find a way to set global env variable from Capistrano. Actual
I have multiple lists. I need to find a way to generate list of
I have a ListView that is fed by an SQLiteDB. On each row returned,
I am using primefaces datatable with clickable rows and I need to find way
I need to find a way to get actual page size in Google Chrome.
I need to find a way to check if the mouse moves in c#,
I need to find a way to spin off a thread from a static
I need to find a way to call a vb.net function in my aspx

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.