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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:40:02+00:00 2026-05-27T06:40:02+00:00

I also want to be able to change the image programmatically so that I

  • 0

I also want to be able to change the image programmatically so that I can attach a listener and change the image at specific points. I’m at the early stages of this and I’m having trouble setting up the view I have;

//inside my activity

LinearLayout mLayout;

//then inside the oncreate

mLayout = (LinearLayout) findViewById(R.id.main1);
setContentView(mLayout);
mLayout.setBackgroundResource(R.drawable.pic);

This compiles fine in eclipse but when I run it the app fails to start.

I’m looking to create a slide show with music.

I have tried the solutions given below but I am still getting an error;

12-06 11:51:11.656: E/AndroidRuntime(238): Uncaught handler: thread main exiting due to uncaught exception

Ultimately I want a slide show that will allow me to set the background image programmatically so I’m trying to get a handle on a view so that I can set the background through a listener.

I have set up a view
res/layout/slider.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main2"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <SeekBar android:id="@+id/seek"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:secondaryProgress="75" />

    <TextView android:id="@+id/progress"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView android:id="@+id/tracking"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

SeekBar mSeekBar;
TextView mProgressText;
TextView mTrackingText;
LinearLayout mLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSeekBar = (SeekBar)findViewById(R.id.seek);
    mSeekBar.setOnSeekBarChangeListener(this);
    mProgressText = (TextView)findViewById(R.id.progress);
    mTrackingText = (TextView)findViewById(R.id.tracking);


    setContentView(R.layout.slider);
    mLayout = (LinearLayout) findViewById(R.id.main2);
    setContentView(mLayout);
    mLayout.setBackgroundResource(R.drawable.mumbai);

    }

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
            mProgressText.setText(progress + " " +
                    getString(R.string.seekbar_from_touch) + "=" + fromTouch);
            //mLayout = (LinearLayout) findViewById(R.id.main1);
            //mLayout.setBackgroundResource(R.drawable.boats);
    }

        public void onStartTrackingTouch(SeekBar seekBar) {
            mTrackingText.setText(getString(R.string.seekbar_tracking_on));
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            mTrackingText.setText(getString(R.string.seekbar_tracking_off));
        }
}

Hi Pratick as I wrote below I’m still getting an error.

12-06 13:02:34.074: E/AndroidRuntime(808): Uncaught handler: thread main exiting due to uncaught exception

Although I don’t think it is very informative. This was after I commented out the second call to setContentView(mLayout).

I’ve just ran it through the debugger and its erred at
mSeekBar.setOnSeekBarChangeListener(this);

I had no success with the suggestions and have tried a new tactic
I’m now trying to use a LayoutInflater but I’m getting the same error on the AVD and when I step through the code Just as I think I’m about to leave the line that calls ‘inflater.inflate’ it gives the error “source not found” and brings up a window in the debugger code pane that allows me to navigate.
I’ve created the 2 views in xml and received no errros when I saved

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PwdDialogActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LayoutInflater inflater = (LayoutInflater) getSystemService
            (Context.LAYOUT_INFLATER_SERVICE);
        final View layout = inflater.inflate(R.layout.password_dialog,
                (ViewGroup)findViewById(R.id.root));
        //layout.setBackgroundResource(R.drawable.boats);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(layout);
        builder.setTitle(R.string.app_name);
    }
}

I’m wondering if this error and the previous error has nothing to do with the code and is more concerned with my set up. But I have created the project and AVD to run in version 3. I’ve looked up LayoutInflater and it says it’s been about since version 1.

  • 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-27T06:40:03+00:00Added an answer on May 27, 2026 at 6:40 am

    without setting any layout in setContentView() and find the object by it’s ID it’s always getting null.

    You need to first set the layout and then get object id from that layout

    setContentView(R.layout.yourlayout); // here set the layout where object or control where defined it
    mLayout = (LinearLayout) findViewById(R.id.main1);
    setContentView(mLayout); // and then you can set that object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to edit an image (png file) from the resources
I want to be able to, being given a path to an image, convert
on my site project I want the user to be able to change the
I want to be able to dynamically place image(s) over another image in my
I want to see if this is possible, i need to change a select
i want to save current date+time into database and also want to retrieve it.
I want to implement a function in the base class but I also want
I want to set the height of asp:panel to auto and I also want
i want to call a batch file from another batch file and also want
I want to add a new feature in a wxPython class. I also want

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.