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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:04:08+00:00 2026-06-04T00:04:08+00:00

I am creating an app that it is throwing an error, activity is not

  • 0

I am creating an app that it is throwing an error, activity is not started. My activity class is:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.videos_layout);
    i = new FirstImage(this);
    c = (ViewFlipper) findViewById(R.id.viewFlipper3);
    back = (Button) findViewById(R.id.button1);
    next = (Button) findViewById(R.id.button2);
    t = (TextView) findViewById(R.id.textView1);
    if(count == 0)
        i.changeImage(R.drawable.human); 
    c.addView(i);
    c.setOnTouchListener(this);
    c.onTouchEvent(event);
    addListenerOnButton();
    }


    private void addListenerOnButton() {
        if (count == 0)
            back.setEnabled(false);
        next.setOnClickListener( new OnClickListener() {

            public void onClick(View arg0) {
                if(count==0){
                i.changeImage(R.drawable.hand);
                back.setEnabled(true);
                count++;

                addListenerOnButton();

                }
                else if (count==1){
                    i.changeImage(R.drawable.tissue);
                    count++;

                    addListenerOnButton();

                }

                else if (count==2){
                    image.setImageResource(R.drawable.cellconstfinal1);
                    count++;

                    addListenerOnButton();


                }
                else if (count==3){
                    //nucleus
                    image.setImageResource(R.drawable.cellconstfinal1);
                    count++;

                    addListenerOnButton();

                }
                else if (count==4){
                    //nchromosome
                    image.setImageResource(R.drawable.hand);
                    count++;

                    addListenerOnButton();

                }
                else
                {   //double helix
                    count++;
                    image.setImageResource(R.drawable.handash1);
                    next.setEnabled(false);

                    addListenerOnButton();

                }

            }
        });

        back.setOnClickListener(new OnClickListener() {


            public void onClick(View arg0) {
                if(count==1){
                    image.setImageResource(R.drawable.human);
                    back.setEnabled(false);
                    count--;

                    addListenerOnButton();

                    }
                    else if (count==2){
                        image.setImageResource(R.drawable.hand);
                        count--;

                        addListenerOnButton();

                    }

                    else if (count==3){
                        image.setImageResource(R.drawable.tissue);
                        count--;

                        addListenerOnButton();


                    }
                    else if (count==4){
                        image.setImageResource(R.drawable.cellconstfinal1);
                        count--;

                        addListenerOnButton();

                    }
                    else if (count==5){
                        //nucleus
                        image.setImageResource(R.drawable.tissue);
                        count--;

                        addListenerOnButton();


                    }
                    else {
                        //chromosome
                        //count==6
                        image.setImageResource(R.drawable.cellconstfinal1);
                        count--;

                        addListenerOnButton();
                        next.setEnabled(true);

                    }
                }
            });
    }




public void pageinfo(float a,float b){

        t.setText(Float.toString(a)+"x"+Float.toString(b)+"y");

    }



public boolean onTouch(View v, MotionEvent me) {
    // TODO Auto-generated method stub
    switch(me.getAction()){
    case MotionEvent.ACTION_DOWN:
        a=me.getX();
        b= me.getY();
        pageinfo(a,b);
        break;
    case MotionEvent.ACTION_MOVE:
        a=me.getX();
        b= me.getY();
        pageinfo(a,b);
        break;
    case MotionEvent.ACTION_UP:
        a=me.getX();
        b= me.getY();
        pageinfo(a,b);
        break;
    case MotionEvent.ACTION_OUTSIDE:
        a=me.getX();
        b= me.getY();
        pageinfo(a,b);
        break;
    default: return false;
    }
    return true;

}
}

My FirstImage class code:

public class FirstImage extends ImageView {

    float a=0; 
    float b=0;
    TextView t;
    ImageView i;

    public FirstImage(Context context) { 
        super(context); 
        t= (TextView) findViewById(R.id.textView1); 
        i= new ImageView (context); 
    } 

    public FirstImage(Context context, AttributeSet attrs) { 
        super(context, attrs);
   } 

    protected void changeImage(int id){ 
        i.setImageResource(id); 
    } 

The stacktrace with the exception:

  05-11 00:21:41.197: E/AndroidRuntime(1142): FATAL EXCEPTION: main
05-11 00:21:41.197: E/AndroidRuntime(1142): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidtablayout/com.example.androidtablayout.VideosActivity}: java.lang.NullPointerException
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.view.View.performClick(View.java:2408)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.view.View$PerformClick.run(View.java:8816)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.os.Handler.handleCallback(Handler.java:587)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.os.Looper.loop(Looper.java:123)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at java.lang.reflect.Method.invokeNative(Native Method)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at java.lang.reflect.Method.invoke(Method.java:521)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at dalvik.system.NativeStart.main(Native Method)
05-11 00:21:41.197: E/AndroidRuntime(1142): Caused by: java.lang.NullPointerException
05-11 00:21:41.197: E/AndroidRuntime(1142):     at com.example.androidtablayout.VideosActivity.onCreate(VideosActivity.java:45)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-11 00:21:41.197: E/AndroidRuntime(1142):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-11 00:21:41.197: E/AndroidRuntime(1142):     ... 18 more
  • 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-04T00:04:10+00:00Added an answer on June 4, 2026 at 12:04 am

    You should always initialize the views in the onCreate method:

    //...
    FirstImage i;
    //...
    
        @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                 setContentView(R.layout.videos_layout);
                 i = new FirstImage(this);
        //...
    

    Also in the FirstImage class initialize those Views in the constructor:

    public FirstImage(Context context) {
        super(context);
       TextView t= (TextView) findViewById(R.id.textView1); // WHERE do you expect to find this view, in which layout?
       ImageView i= new ImageView (context); //NEVER pass a null Context
    }
    

    Edit:

    My advice is to follow some tutorials for custom Views. You can’t add other Views to an ImageView subclass(and you shouldn’t). Even if you build the ImageView in the FirstImage the changeImage method will throw a NullPointerException the way your code is currently built.

    A simple custom view:

     public class FirstImage extends LinearLayout {
        float a=0; 
        float b=0;
    
        TextView t;
        ImageView i;
    
        public FirstImage(Context context) { 
            super(context); 
            t = (TextView) findViewById(R.id.textView1); // What is with this TextView?!?
            i = new ImageView (context); 
            LinearLayout.LayoutParams lp = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            addView(i, lp);   
        } 
    
    protected void changeImage(int id){ 
        i.setImageResource(id); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm creating a web app that's running on an Advantage Database server, not my
I'm creating android app that has table layout for the main activity, and that
I'm creating an app that creates buttons through code when an activity starts (the
I'm creating an app that is threaded. I started GUI (Announce : Form) as
I'm creating and app that will rely on a database, and I have all
I am creating an app that is having a UIWebView which contains an advert.
I am creating an app that runs on the logitech revue. The UI is
I'm creating an app that lets users take and store photos in a Core
I am creating an app that has three tabs on the main screen. Each
I'm creating an app that creates and saves images. Currently I am saving them

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.