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

  • Home
  • SEARCH
  • 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 8245941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:20:51+00:00 2026-06-07T22:20:51+00:00

I have been working on an app which requires finding the height and width

  • 0

I have been working on an app which requires finding the height and width of different devices. If I remove the code for height and width the app works if i include the code the app crashes.

Can you please suggest what’s wrong with the code.

Here’s the code:

public class Newone extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newone);
    }

    final Context context = this;
    public String cntry = "";
    int w= getWindowManager().getDefaultDisplay().getWidth();
    int h = getWindowManager().getDefaultDisplay().getHeight();

    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    int w = metrics.widthPixels;
    int h = metrics.heightPixels;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        MotionEvent object holds X-Y values
        if(event.getAction() == MotionEvent.ACTION_DOWN) {              
            String text = "You click at x = " + event.getX() + " and y = " + event.getY();
            //Toast.makeText(this, text, Toast.LENGTH_LONG).show();

            if((event.getX()>((w/1280)*850)) && (event.getX()<((h/752)*900)) && (event.getY()>((w/1280)*380)) && (event.getY()<((h/752)*450)))
                if((event.getX()>850) && (event.getX()<900) && (event.getY()>380) && (event.getY()<450)) {
                    Toast.makeText(this, text, Toast.LENGTH_LONG).show();
                    display(cntry);
                }

                if((event.getX()>280) && (event.getX()<400) && (event.getY()>200) && (event.getY()<300)) {
                    //Toast.makeText(this, text, Toast.LENGTH_LONG).show();
                    cntry = "US";
                    display(cntry);
                }

                if((event.getX()>900) && (event.getX()<1200) && (event.getY()>500) && (event.getY()<650))
        }
        return super.onTouchEvent(event);
    }   

    private void display(final String cntry) {
        final Dialog dialog = new Dialog(context);
        dialog.show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_newone, menu);
        return true;
    }

}
  • 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-06-07T22:20:53+00:00Added an answer on June 7, 2026 at 10:20 pm

    What if you move getWindowManager().getDefaultDisplay().getWidth(); and getHeight() and metrics = context.getResources().getDisplayMetrics(); inside you onCreate ? I’m not sure context and others are available at the Activity‘s construction time.

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

Sidebar

Related Questions

I have been working on an app which includes using the devices camera. After
I have been working on test framework, which creates a new app domain to
I have been working on an app all day which has been working fine
I have recently been working on a nodejs app which uses open socket connections
I have an MFC app which I have been working on for a few
I have been working on a Spotify app which displays a track listing using
I have been working on this app for at least 3-4 months and just
I have been working on an app where I have successfully shown my location
I have been working on an iOS App for sometime now and its almost
I have been working on a django app on my local computer for some

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.