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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:08:05+00:00 2026-05-26T09:08:05+00:00

Im trying to make my alertdialog in a separate class than my main class

  • 0

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.

Here is the code for the alert dialog:

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();
    }
    }

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):

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;
    }
  • 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-26T09:08:06+00:00Added an answer on May 26, 2026 at 9:08 am

    You are passing context as null, that is the problem. Give some appropriate value and you will not get it probably.

        PlacepinDialog alertDialog = new PlacepinDialog(null);
    
    public PlacepinDialog(Context context)
    
    builder = new AlertDialog.Builder(context); // context is null.
    

    These lines are picked from your code. This is causing the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying make my first python app. I want make simple email sender form.
I'm trying to make an alert box that appears only when the app is
I'm trying to make an app which on a click of a list item
Trying to make td elements clickable. Here's my HTML: <td id=A3 class= open-square><a href=/gameplay/A3></a></td>
Trying to make a Grid Like this using java and I'm assuming a 2d
Trying to make a regex that can handle input like either: Beverly Hills, CA
I am trying to make an app where when the user taps on a
Trying to make a simple program to catalogue books. Something like this, for example:
I am trying make long screen to vertical direction. So, I need a screen
Trying to make a make generic select control that I can dynamically add elements

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.