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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:19:44+00:00 2026-05-25T03:19:44+00:00

Allright som first of im very new to android programming and was trying to

  • 0

Allright som first of im very new to android programming and was trying to do something pretty simple and basic. A program which contains various pictures, and depending on which button you click its showed. Instead of creating a new xml file for every picture I wanted to set as background I thought about just making one xml file, and then calling for it to change the background. so what I was trying to use was this:

public class Picture extends Activity{
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent=getIntent();
    int picture=intent.getIntExtra("picture", 22);
    ImageView image = (ImageView) findViewById(R.id.pansarvagn);
    image.setBackgroundResource(picture);
    setContentView(R.layout.tmp2);
 }
}

and then ive made this:

public void displayPicture(int pictureresource){
Intent intent = new Intent();
intent.putExtra("picture", pictureresource);
intent.setClass(getApplicationContext(), Picture.class);
startActivity(intent);
}

and finally a button call looks like this:

 ImageView image = (ImageView) findViewById(R.id.pansarvagn);

    Button spgsu8 = (Button) findViewById(R.id.su8);
    spgsu8.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

    image.setBackgroundResource(R.drawable.su8);
    displayPicture(R.drawable.su8);

and then this is in my xml file, or well i tried a bunch of stuff but i want to call on the id and change the pic/background:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/su8" android:id="@+id/pansarvagn"></ImageView>

but no matter how I twist it I still come up with:

08-30 06:47:07.568: ERROR/AndroidRuntime(449): java.lang.RuntimeException: Unable to start     activity ComponentInfo{com.example.wot/com.example.wot.Picture}: java.lang.NullPointerException
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.os.Looper.loop(Looper.java:123)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at java.lang.reflect.Method.invoke(Method.java:507)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at dalvik.system.NativeStart.main(Native Method)
08-30 06:47:07.568: ERROR/AndroidRuntime(449): Caused by: java.lang.NullPointerException
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at com.example.wot.Picture.onCreate(Picture.java:17)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-30 06:47:07.568: ERROR/AndroidRuntime(449):     ... 11 more

I hope you guys can make sence of this :>

  • 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-25T03:19:45+00:00Added an answer on May 25, 2026 at 3:19 am

    try below code … we cant define any view before setcontentview

    public class Picture extends Activity{
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent=getIntent();
        int picture=intent.getIntExtra("picture", 22);
        setContentView(R.layout.tmp2);  
        ImageView image = (ImageView) findViewById(R.id.pansarvagn);
        image.setBackgroundResource(picture);
    
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Allright, I'm completely new to programming but I feel I am picking it up
Alright I don't see why this isnt working. It seems pretty simple. Here is
I am trying to read the UDP packages in python, which were sent from
ANSWER: Allright, that was quite simple (probably I made this mistake coz I need
My current employer wants to use JavaDB for his new project. Allright with it,
I'm building a android application that need to look allright on all screen sizes.
I am very new to Quartz and I have some doubts about the jobs
Alright, so I got this code for gluLookAt: lookAt = new Vector3f(-player.pos.x, -player.pos.y, -player.pos.z);
Alright, here I am again trying to write code from scratch and I can't
Allright, this is like thousandth time when I get kinda useless information from a

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.