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

The Archive Base Latest Questions

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

I have one activity/java file (Browsefile.java) that would obtain the absolute path of the

  • 0

I have one activity/java file (Browsefile.java) that would obtain the absolute path of the file. I want to pass this information to another java file for further processing (Sqlitefun.java). In the first stage, I just want to make sure the variable of file path is passed from Browsefile.java to Sqlitefun.java so I just create an alertdialog in the Sqlitefun.java file to test it. However, I have some issue on the context of the alertdialog object.

(As Sqlitefun.java would further perform i/o and Sqlite processing tasks, I prefer to put this in another file.)

Here are the codes for the files:

Browsefile.java

public class Browsefile extends ListActivity {
....

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browsefile);
    findViews(); 
    getDir(root);

}
....
@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
        {
            selectpath = file.getAbsolutePath();
            fpath.setText(selectpath);  
        }
    }
    else
    {
        selectpath = file.getAbsolutePath();
        fpath.setText(selectpath);
    }       
}       

private Button.OnClickListener importcsv = new Button.OnClickListener() {
    public void onClick(View v) {
        Sqlitefun firstClass = new Sqlitefun();
            firstClass.getsAlertDialog(selectpath); 
    }
};
....
}

Sqlitefun.java

public class Sqlitefun {

private Context context;

public void getsAlertDialog(String filepath) {

    new AlertDialog.Builder(context)
    .setMessage(filepath)
    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

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

}

I have tried to use this, Sqlitefun.this to replace context in the line new AlertDialog.Builder(context) but none of this works. (Eclipse said The constructor AlertDialog.Builder(Sqlitefun) is undefined and did not allow me to compile. The above code did not have any error and allow me to compile, but there is a nullpointer exception for the Context.

  • 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-27T15:10:56+00:00Added an answer on May 27, 2026 at 3:10 pm

    I believe you need to show dialogs from the Activity you are currently in, so you would need to the put AlertDialog code in BrowserFile.

    I’m not sure if this would work, but you could try passing the context from BrowserFile to SqliteFun and showing it there.

    Additionally, if you’re not set on using an AlertDialog, trying using a Toast notification instead. They generally do better when used outside of an Activity.

    Edit: I don’t think the following is the best way to implement what you are trying to do, but here is a code sample I wrote

    In SqliteFun, modify your method as such:

    public void getsAlertDialog(String filepath, Context mContext) {

    new AlertDialog.Builder(mContext)
    .setMessage(filepath)
    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
    
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        }
    })
    .show();
    } 
    

    Then from your Activity, use this:

    private Button.OnClickListener importcsv = new Button.OnClickListener() {
    public void onClick(View v) {
        Sqlitefun firstClass = new Sqlitefun();
            firstClass.getsAlertDialog(selectpath, v.getContext()); 
    }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Think that I have many activities,and all I want is this: I have a
My situation is following. I have one Activity that contains three main parts. At
Actually I have two java classes of which one is an activity class. Now
Cant figure this out (am a noob) but I have a default activity that
I am working on activity which request one php file on server & this
I have a levels.java file where the user can pick one of 3 levels,
I have an a Java Android app that calls different activities. I thought this
I am trying to save a date in one activity and then have that
I have to include one report in my application showing offline/online activity of few
I have one field that I need to sum lets say named items However

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.