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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:13:31+00:00 2026-05-25T18:13:31+00:00

I’m trying to implement a SeekBar in a simple flashlight app (that I’m learning

  • 0

I’m trying to implement a SeekBar in a simple flashlight app (that I’m learning on) and cannot understand why the app keeps crashing when I set the OnSeekBarChangeListener to my SeekBar. As soon as a remove all of the code inside the onStopTrackingTouch() for the listener, the app runs fine. But if there is anything at all inside the listener’s methods, it crashes. I’m also using buttons and gestures in the app and have not had any problems using those.

I am bringing up a separate layout when the user presses the Menu button | Brightness option, which displays the SeekBar (to adjust the brightness)

Here is the how I am implementing the SeekBar:

SeekBar mSeekBar;

...

@Override 
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.main);

...

mSeekBar = (SeekBar)findViewById(R.id.mSeekbar);
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                //first set the brightness mode to manual
                Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

                //change the actual setting
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                float brightness = Float.valueOf(seekBar.getProgress()); //change the brightness here
                lp.screenBrightness = brightness;
                getWindow().setAttributes(lp); //set the new brightness
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
            }
        });

Thank you for your time and advice.

UPDATE: Here is the link to my Logcat info http://pastie.org/2561098

UPDATE 2: Here is the link to my release run LogCat info: http://pastie.org/2561111

SOLVED:

I had mSeekBar being instantiated and the listener’s set before the layout was present. The SeekBar was null because the separate layout I made for adjusting the brightness was not currently in view. Putting the instantiation and listener’s inside the switch statement I use for options menu, after the new layout (for the brightness) is set works perfectly.

Thank you!

  • 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-25T18:13:32+00:00Added an answer on May 25, 2026 at 6:13 pm

    There is your answer. On line 77 of your onCreate method your program is crashing because of a NullPointerException. The answer is in the stack trace, while these look perplexing, they actually point you to the exact line of code that caused the crash (most of the time).

    at com.polaniec.myflashlight.MyFlashLightActivity.onCreate(MyFlashLightActivity.java:77)
    

    When you dig through the stack trace you want to look for the part that indicates YOUR actual class name and method name (not all of the android.os… or java.lang… methods). The 77 means it is line 77 in your code. Whatever you are referencing is null, maybe it was not instantiated?

    Hope this helps!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace

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.