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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:28:43+00:00 2026-06-17T07:28:43+00:00

I am doing an android app and i was thinking of creating a theme

  • 0

I am doing an android app and i was thinking of creating a theme option. Well all I was thinking of doing was to allow the user to click on a image button which represented a theme. And when he clicks on it I start a new activity i.e i direct him to the home page. Also i have created a few integer variables which are set to 1 when the user clicks on a button.

Then in the other classes all i do is check if the variables are 1 or not and depending on that i apply the theme. By theme i mean i just change the background wallpaper. But this is not working. I mean the code works but if use an if loop to check the variable values and then apply the effects it causes an error.

Here’s the complete code:

package com.example.themetest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;

public class MainActivity extends Activity implements OnClickListener{

    ImageButton ib1;
    ImageButton ib2;
    int water=0;
    int fire=0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ib1 = (ImageButton) findViewById(R.id.imageButton1);
        ib2 = (ImageButton) findViewById(R.id.imageButton2);
        ib1.setOnClickListener(this);
        ib2.setOnClickListener(this);



    }


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch(v.getId()){
        case R.id.imageButton1:
            water = 1;
            Intent wi = new Intent("com.example.themetest.THEME");
            startActivity(wi);
            break;

        case R.id.imageButton2:
            fire = 1;
            Intent fi = new Intent("com.example.themetest.THEME");
            startActivity(fi);
            break;
        }
    }



}

Here’s the other class where i check which variable is set to 1 and apply the effect.

package com.example.themetest;

import java.io.InputStream;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.LinearLayout;

public class Theme extends Activity{

    MainActivity main;
    Resources res;
    Drawable drawable;
    LinearLayout linearLayout;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.theme);

        if(main.water==1){


            res = getResources(); 
            drawable = res.getDrawable(R.drawable.water_theme); 
            linearLayout =   (LinearLayout)findViewById(R.id.ll); 
            linearLayout.setBackgroundDrawable(drawable);
            }
            else if(main.fire==1){
                res = getResources(); 
                drawable = res.getDrawable(R.drawable.fire_theme); 
                linearLayout =   (LinearLayout)findViewById(R.id.ll); 
                linearLayout.setBackgroundDrawable(drawable);
        }
            else{
                res = getResources(); 
                drawable = res.getDrawable(R.drawable.ic_launcher); 
                linearLayout =   (LinearLayout)findViewById(R.id.ll); 
                linearLayout.setBackgroundDrawable(drawable);
        }

    }



    }

I can change the wallpaper without using the if loop, but i want to do it this way which is not working. Can anyone please tell me why?

Log cat:

01-15 12:08:23.339: D/dalvikvm(273): GC_EXTERNAL_ALLOC freed 767 objects / 55936 bytes in 235ms
01-15 12:08:25.539: D/AndroidRuntime(273): Shutting down VM
01-15 12:08:25.539: W/dalvikvm(273): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-15 12:08:25.559: E/AndroidRuntime(273): FATAL EXCEPTION: main
01-15 12:08:25.559: E/AndroidRuntime(273): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.themetest/com.example.themetest.Theme}: java.lang.NullPointerException
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.os.Looper.loop(Looper.java:123)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-15 12:08:25.559: E/AndroidRuntime(273):  at java.lang.reflect.Method.invokeNative(Native Method)
01-15 12:08:25.559: E/AndroidRuntime(273):  at java.lang.reflect.Method.invoke(Method.java:521)
01-15 12:08:25.559: E/AndroidRuntime(273):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-15 12:08:25.559: E/AndroidRuntime(273):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-15 12:08:25.559: E/AndroidRuntime(273):  at dalvik.system.NativeStart.main(Native Method)
01-15 12:08:25.559: E/AndroidRuntime(273): Caused by: java.lang.NullPointerException
01-15 12:08:25.559: E/AndroidRuntime(273):  at com.example.themetest.Theme.onCreate(Theme.java:29)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-15 12:08:25.559: E/AndroidRuntime(273):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-15 12:08:25.559: E/AndroidRuntime(273):  ... 11 more
01-15 12:08:31.089: I/Process(273): Sending signal. PID: 273 SIG: 9
  • 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-17T07:28:44+00:00Added an answer on June 17, 2026 at 7:28 am

    You cannot access other activities variables this way, a better way (for example) is to use a constant class..

    public class Constants {
        public static int water=0;
        public staticint fire=0;
    }
    

    MainActivity:

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
    
        switch(v.getId()){
        case R.id.imageButton1:
            Constants.water = 1;
            Intent wi = new Intent("com.example.themetest.THEME");
            startActivity(wi);
            break;
    
        case R.id.imageButton2:
            Constants.fire = 1;
            Intent fi = new Intent("com.example.themetest.THEME");
            startActivity(fi);
            break;
        }
    }
    

    Theme:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.theme);
    
        if(Constants.water==1){
    
    
            res = getResources(); 
            drawable = res.getDrawable(R.drawable.water_theme); 
            linearLayout =   (LinearLayout)findViewById(R.id.ll); 
            linearLayout.setBackgroundDrawable(drawable);
            }
            else if(Constants.fire==1){
                res = getResources(); 
                drawable = res.getDrawable(R.drawable.fire_theme); 
                linearLayout =   (LinearLayout)findViewById(R.id.ll); 
                linearLayout.setBackgroundDrawable(drawable);
        }
            else{
                res = getResources(); 
                drawable = res.getDrawable(R.drawable.ic_launcher); 
                linearLayout =   (LinearLayout)findViewById(R.id.ll); 
                linearLayout.setBackgroundDrawable(drawable);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing an android app, I want to drag an image and place
I am trying to create an app which will allow a user to view
I am doing a location search from my android app. User enter an address
I'm doing a small Android app based around a ListView. When the user selects
I am doing push notification for android using C2DM. it works well. but while
I have an android app where I am doing the following: private void onCreate()
I am doing a custom title for my android app and I want to
I'm doing what seems like simple math in an android app, however I keep
i'm working on a android app that will display Strings to the user, and
I have an app which I want to run on as many Android phones

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.