You are invoking the findViewById()
method in the wrong way. It should be invoked on the Activity
itself, not on the Button
reference. Replace
b1=(Button) b1.findViewById(R.id.button);
with
b1=(Button) findViewById(R.id.button);
The b1
reference is null at that point, and is the reason for the NullPointerException
.
More Related Contents:
- The constructor JSONArray(Object[]) is undefined
- Can’t add parameter ‘this’
- How to paginate Firestore with Android?
- Checking if a particular value exists in the Firebase database
- java.lang.ClassNotFoundException: Didn’t find class on path: dexpathlist
- How to convert a color integer to a hex String in Android?
- How does Activity.finish() work in Android?
- How to get frequency from fft result?
- Android Studio Error: Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you’re running
- Code will only return 0.0, 0.0 GPS coordinate while throwing NullPointerException
- How to specify the JDK version in Android Studio?
- How to delete a file on google drive using Google Drive Android API
- How one interface can be used for different background android tasks?
- Android AudioRecord class – process live mic audio quickly, set up callback function
- Is there on install event in android?
- Android Center text on canvas
- Difference between ActionBarSherlock and ActionBar Compatibility
- How do you simulate low memory in the Android emulator?
- method called after release() exception unable to resume with android camera
- Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments
- how to update xml file from another xml file dynamically?
- Changing OpenSSL library in Android app for HttpClient
- Android flood-fill algorithm [closed]
- The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption
- Getting the current time millis from device and converting it into a new date with different timezone [duplicate]
- How to exclude an element from a Firestore query?
- GPS Android – get positioning only once
- incompatible types: HomeFragment cannot be converted to Fragment in Android
- Broadcast Intent when network state has changend
- Asynctask: pass two or more values from doInBackground to onPostExecute