Note that there are some explanatory texts on larger screens.

plurals
  1. POCall alertdialog in another .java file
    primarykey
    data
    text
    <p>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.</p> <p>(As Sqlitefun.java would further perform i/o and Sqlite processing tasks, I prefer to put this in another file.)</p> <p>Here are the codes for the files:</p> <p><strong>Browsefile.java</strong></p> <pre><code>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); } }; .... } </code></pre> <p><strong>Sqlitefun.java</strong></p> <pre><code>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(); } } </code></pre> <p>I have tried to use <code>this</code>, <code>Sqlitefun.this</code> to replace <code>context</code> in the line new <code>AlertDialog.Builder(context)</code> but none of this works. (Eclipse said <code>The constructor AlertDialog.Builder(Sqlitefun) is undefined</code> and did not allow me to compile. The above code did not have any error and allow me to compile, but there is a <code>nullpointer</code> exception for the Context. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload