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