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.