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 8855211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:04:59+00:00 2026-06-14T14:04:59+00:00

I get a null pointer exception in the deleteIt method in the filelist.notifyDataSetChanged(); I

  • 0

I get a null pointer exception in the deleteIt method in the filelist.notifyDataSetChanged();

I need some help trying to remove the file, please be kind. It took me a couple of hours how to add the longclick method. This could could be used by someone but I need to help with the removing item from list.

public class AndroidExplorer extends ListActivity 
{

private List<String> item = null;
private List<String> path = null;
private TextView myPath;

ArrayAdapter filelist = null;

File myFile = new   File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/GV-Skynet");
String root2 = myFile.getAbsolutePath();;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    myPath = (TextView)findViewById(R.id.path);
    getDir(root2);


    ListView list = getListView();
    list.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id) 
        {
            File file = new File(path.get(position));

            deleteIt("Do you want to Delete", file.getName(), file );
            return true;
        }
    });

}

private void showToast(String msg) 
{
    Toast error = Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG);
    error.show();
}

private void getDir(String dirPath)
{
    myPath.setText("Location: " + dirPath);

    item = new ArrayList<String>();
    path = new ArrayList<String>();

    File f = new File(dirPath);
    File[] files = f.listFiles();

    if(!dirPath.equals(root2))
    {
        item.add("Return to GV-Skynet Directory");
        path.add(f.getParent());
    }

    for(int i=0; i < files.length; i++)
    {
        File file = files[i];
        path.add(file.getPath());
        if(file.isDirectory())
            item.add(file.getName() + "/");
        else
            item.add(file.getName());
    }

    ArrayAdapter<String> fileList =
        new ArrayAdapter<String>(this, R.layout.row, item);
    setListAdapter(fileList);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) 
{

    File file = new File(path.get(position));

    if (file.isDirectory())
    {
        if(file.canRead())
            getDir(path.get(position));
        else
        {
            new AlertDialog.Builder(this)
            .setIcon(R.drawable.icon)
            .setTitle("[" + file.getName() + "] folder can't be read!")
            .setPositiveButton("OK", 
                    new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }
            }).show();
        }
    }
    else
    {

        String fileName = file.getName();
        String fname="";
        String ext="";
        int mid= fileName.lastIndexOf(".");
        fname=fileName.substring(0,mid);
        ext=fileName.substring(mid+1,fileName.length());



        if(ext.equals("jpg"))
        {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);

            Uri uri = Uri.fromFile(file);
            intent.setDataAndType (uri, "image/*");
            this.startActivity(intent); 
        }

        if(ext.equals("3gp"))
        {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra ("oneshot", 0);
            intent.putExtra ("configchange", 0);
            Uri uri = Uri.fromFile(file);
            intent.setDataAndType (uri, "video/*");
            this.startActivity(intent);
        }

    }
}

public void deleteIt( String title, String name, File file )
{
    final String name1 = name;
    final File tmFile = file;
    new AlertDialog.Builder(this)
    .setTitle(title)
    .setMessage(name1)
    .setPositiveButton("YES", new DialogInterface.OnClickListener() // OnClickListener()
    {
        public void onClick(DialogInterface arg0, int arg1) 
        {
            //item = new ArrayList<String>();
            item.remove(tmFile.getName()); // remove the item
            filelist.notifyDataSetChanged(); // let the adapter know to update

            showToast("File Deleted: " + tmFile.getName() );
        }
    })
    .setNegativeButton("NO", new DialogInterface.OnClickListener() // OnClickListener()
    {
        public void onClick(DialogInterface arg0, int arg1) {
            // do stuff onclick of CANCEL
            showToast("CANCELLING DELETE");
        }
    }).show();
}

}
  • 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-06-14T14:05:01+00:00Added an answer on June 14, 2026 at 2:05 pm

    just try this change your statement

    ArrayAdapter filelist = null;
    

    with

    ArrayAdapter<String> filelist = null;
    

    and also you are re-declaring filelist in your getDir method so change it to

    filelist = new ArrayAdapter<String>(this,R.layout.row, item);
        setListAdapter(filelist);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get a null pointer exception when a call a method on a custom
I'm trying to implement an interface, but I get the 'Null-pointer' exception, but I
I get null pointer exception at line mService.start() when i try to bind to
I get a null pointer exception and the program crash on each time I
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
When I run the following code I get Null Pointer Exception. I cannot figure
I sometimes get a null pointer exception with my code. Oddly enough, this does
I want to create 2D array of objects, but i get null pointer exception
Can someone please tell my why I'm getting a null pointer exception with this
I was just trying to figure out if I could get a NULL pointer

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.