-1

I have a problem with my project on Android Studio. Every time I run the app, it starts up perfectly normal, no build errors at all, however, upon clicking a button on the Main Activity to go to another activity, the app stops. I have checked Logcat for the issue and it states that -

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.opendayapp.openday/com.opendayapp.openday.FAQ}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference 
at com.opendayapp.openday.FAQ.configureContactButton(FAQ.java:55)
at com.opendayapp.openday.FAQ.onCreate(FAQ.java:20)

Here is some code from that project that Logcat has checked that might have an issue with it

Public Class

public class FAQ extends AppCompatActivity {


    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_faq);
        configureHomeButton();
        configureContactButton();

        webView = (WebView) findViewById(R.id.webViewInformation);

        WebSettings webSettings = webView.getSettings();
        webSettings.setBuiltInZoomControls(true);
        //webSettings.setJavaScriptEnabled(true);

        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("file://asset/information.html");
    }

Here's another part of the code that Logcat highlighted to have an issue with

        Button contactButton = (Button) findViewById(R.id.btnContact);
        contactButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            Intent i2 = new Intent(FAQ.this, Contact.class);
            startActivity(i2);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_in_left);
            }
        });
    }

Is there a fix for this, as I am stuck for a way to resolve this. Many feedback and criticism will be very helpful for future references

Thanks in advance

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
ethanj
  • 1

1 Answers1

0

It looks like the button for which you are trying to set the onClick listener does not exist in your layout file. Or if it exist, you are using the wrong id in your activity class. Make sure that the id of the button is btnContact in your layout file as you have used in your activity.

Ezio
  • 2,837
  • 2
  • 29
  • 45
  • I have checked my buttons and yes you are correct, I was using the wrong one. Logcat is now not showing that line anymore, however, I have another problem, this one is to do with the Webview – ethanj May 21 '19 at 18:21