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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:41:54+00:00 2026-06-08T17:41:54+00:00

I cannot figure out why these 2 buttons are not working, i have a

  • 0

I cannot figure out why these 2 buttons are not working, i have a layout file inwhich is created when the user selects a certain theme in my application. With the layout it has a webview it has 2 buttons to goback and goforward.

   <Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:text="Back" 
    android:layout_alignParentLeft="true" 
    android:layout_height="wrap_content" 
    android:background="@drawable/button_blue" 
    style="@style/ButtonText">
  </Button>

  <Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:background="@drawable/button_blue"
    style="@style/ButtonText" 
    android:text="Forward">
 </Button>


  <WebView
    android:id="@+id/webview01"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1.12" >

This is not the entire layout file, but here is the bit of stuff i am working with for the webview and the 2 buttons, now inside my main activity here is my button code.

      @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (Prefs.theme.equals("Theme1"))
        setContentView(R.layout.main);
    else if (Prefs.theme.equals("Theme2"))
        setContentView(R.layout.main2);
    else if (Prefs.theme.equals("Theme3"))
        setContentView(R.layout.main3);
    else setContentView(R.layout.main);



    btnForward=(Button) findViewById (R.id.button1);
    btnBackward=(Button) findViewById (R.id.button2);
    btnForward.setOnClickListener(this);
    btnBackward.setOnClickListener(this);


    // more code within on create .....

// Later in the code 

public void onClick(View v) {

    switch(v.getId()) {

        case R.id.button1:
            WebViewClientDemoActivity.web.goBack();
           break;

        case R.id.button2:
            WebViewClientDemoActivity.web.goForward();
           break;
    }

//

I problem im having is by default it loads main.xml not main3 (which is were the 2 buttons are)

LogCat Errors

  07-27 16:00:34.802: E/AndroidRuntime(547): FATAL EXCEPTION: main
  07-27 16:00:34.802: E/AndroidRuntime(547): java.lang.RuntimeException: Unable to start activity       ComponentInfo{com.jaisonbrooks.enlighten/com.jaisonbrooks.enlighten.WebViewClientDemoActivity}: java.lang.NullPointerException
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.os.Handler.dispatchMessage(Handler.java:99)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.os.Looper.loop(Looper.java:123)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.ActivityThread.main(ActivityThread.java:3683)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at java.lang.reflect.Method.invoke(Method.java:507)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at dalvik.system.NativeStart.main(Native Method)
  07-27 16:00:34.802: E/AndroidRuntime(547): Caused by: java.lang.NullPointerException
  07-27 16:00:34.802: E/AndroidRuntime(547):    at com.jaisonbrooks.enlighten.WebViewClientDemoActivity.onCreate(WebViewClientDemoActivity.java:75)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  07-27 16:00:34.802: E/AndroidRuntime(547):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  07-27 16:00:34.802: E/AndroidRuntime(547):    ... 11 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-08T17:41:56+00:00Added an answer on June 8, 2026 at 5:41 pm

    First in your onCreate method find your buttons by ids :

    public class YourActivity extends Activity implements OnClickListener {
    Button btnForward;
    Button btnBackward;
    
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            btnForward=(Button) findViewById (R.id.btnForward);
            btnBackward=(Button) findViewById (R.id.btnBackward);
    
            //set listeners
            btnForward.setOnClickListener(this);
            btnBackward.setOnClickListener(this);
    
            // your code here .... 
        }
    
    @Override
    public void onClick(View v ) {
         switch(v.getId()) {
    
            case R.id.btnBackward:
                WebViewClientDemoActivity.web.goBack();
               break;
            case R.id.btnForward:
                WebViewClientDemoActivity.web.goForward();
               break;
        }
    }
    

    }

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

Sidebar

Related Questions

I cannot figure out what is obscuring my buttons. The first image shows the
I cannot figure out how to get rid of errors that should not be
I have a question that might seem basic but I just cannot figure out
I cannot for the life of me figure out why this markup is not
I have read a ton about this problem, but I cannot figure it out.
Cannot figure out, where to change EOF in PyCharm. My scripts start with :
I cannot figure out this positioning problem in Firefox. It doesn't seem to follow
I cannot figure out why this doesn't work. It seems so simple. It should
I cannot figure out how to write the following query using the DbFinderPlugin 1.2.2
I cannot figure out why I get this error during check-in. I checked in

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.