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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:26:21+00:00 2026-05-26T21:26:21+00:00

class PlayAreaView extends View{ private static final String DEBUG_TAG = PlayAreaView; private SeekBar sizeSlider;

  • 0
class PlayAreaView extends View{  
    private static final String DEBUG_TAG = "PlayAreaView";
    private SeekBar sizeSlider;
    private int xMin = 0;
    private int xMax;
    private int yMin = 0;
    private int yMax;

    private Rect rect;
    private GestureDetector gestures;
    private Paint p = new Paint();
    private int side = 50;

    public PlayAreaView(Context context){
        super(context);
        rect = new Rect(0,0,side,side);
        p.setARGB(255, 255, 255, 255);
        GestureListener listener = new GestureListener(this);
        gestures = new GestureDetector(listener);
        sizeSlider = (SeekBar) findViewById(R.id.seek);
        //sizeSlider.setOnSeekBarChangeListener(listener);
    }

I am new to developing on Android and am having trouble figuring out what is wrong here. I am getting a NullPointerException at the commented out line. I believe it is because I am asking to findViewById in a class that is not the main activity. If this is indeed the problem how can I access UI elements from this class.

  • 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-26T21:26:21+00:00Added an answer on May 26, 2026 at 9:26 pm

    As you have set up, findViewById(R.id.seek) will search for a subview with ID equal to R.id.seek within PlayAreaView, which does not exist since you seem to have the SeekBar in your main layout.

    If you must access The SeekBar from within this view, pass in a reference to it while instantiating it, e.g., in the main activity

    SeekBar sizeSlider = (SeekBar)findViewById(R.id.seek);
    PlayAreaView areaView = new PlayAreaView(this, sizeSlider);
    

    and in PlayAreaView,

    SeekBar sizeSlider;
    
    public PlayAreaView(Context context, SeekBar seekBar) {
      super(context);
      sizeSlider = seekBar;
      ...
      seekBar.setOnSeekBarChangeListener(...);
    }
    

    then, the SeekBar instance can be accessed through the instance variable sizeSlider from PlaAreaView.

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

Sidebar

Related Questions

{ class Program { static void Main(string[] args) { int id = 0, stock
class Foo { final String s; final int x = s.length(); Foo(String s) {
class Program { static void Main(string[] args) { Console.WriteLine(Fib 1: ); Console.ReadLine(); } long
class Test extends JPanel implements MouseListener { private JButton b1, b2, b3, b4; public
Class Account extends CI_Model { private $tbl_rest = array(); private $tbl_fields = array('bs_id', 'bs_name',
class A { public static void main(String[] args) { A a = new A();
Class c extends thread static Queue<Socket> socketQueue Make connection to another server or client
class ZiggyTest{ public static void main(String[] args){ RunnableThread rt = new RunnableThread(); Thread t1
class ZiggyTest{ public static void main(String[] args) { String str = aaaaaaaaabb; String []
class foo { public: void set(const int a) {b=a;} private: int b; }; Here

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.