Note that there are some explanatory texts on larger screens.

plurals
  1. POCatching exceptions when using AlertDialog?
    primarykey
    data
    text
    <p>Im trying to make my alertdialog in a separate class than my main class and when it gets called it also gets and error and the app stops, I would like to know how i would catch the exception or how i would find the error in a code like this.</p> <p>Here is the code for the alert dialog:</p> <pre><code>import android.app.AlertDialog; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class PlacepinDialog extends AlertDialog{ AlertDialog.Builder builder; AlertDialog alertDialog; TextView text; ImageView image; Button place; Button cancel; LayoutInflater inflater; View layout; public PlacepinDialog(Context context) { super(context); //Setting up View and Inflater LayoutInflater inflater = (LayoutInflater)getLayoutInflater(); View layout = inflater.inflate(R.layout.placepin_dialog, (ViewGroup) findViewById(R.id.mvMain)); //Text Views TextView text = (TextView) layout.findViewById(R.id.Placetext); text.setText("Do you want to place a pin at the location you pressed?"); //Image Views ImageView image = (ImageView) layout.findViewById(R.id.Placeimage); image.setImageResource(R.drawable.icon); //Building the Dialog builder = new AlertDialog.Builder(context); builder.setView(layout); alertDialog.setTitle("Place Pin"); alertDialog = builder.create(); } } </code></pre> <p>here is where the alertdialog gets called(this onTouchEvent is in another class than the main class so i can't just do main.this):</p> <pre><code>public boolean onTouchEvent(MotionEvent e, MapView mv){ int i = e.getAction(); switch(i){ case MotionEvent.ACTION_DOWN: //When your finger touches the screen Log.d("ACTION DOWN", "Finger touched screen"); break; case MotionEvent.ACTION_UP: //When your finger stop touching the screen Log.d("ACTION UP", "Finger was removed from screen"); try{ PlacepinDialog alertDialog = new PlacepinDialog(null); } catch(){ } break; case MotionEvent.ACTION_MOVE: //When your finger moves around the screen Log.d("ACTION MOVE", "Finger was moved around the screen"); break; } return false; } </code></pre>
    singulars
    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.
    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