Here are some things you might have forgotten to do:
- Name your button (give it an id), I think they’re named button1, button2, … by default
- Use a capital B when declaring the button object:
Button myButton = new Button("play music");
You should make sure you have Button imported in the activity where you want a button (I think you do)
You can add a button with xml, like so:
<Button android:id="@+id/button_id" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/play_music_button" />
Related Posts:
- align text center with android
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- How to set menu to Toolbar in Android
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- Converting double to string
- Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
- Error parsing data org.json.JSONException: Value
- What does “|=” mean? (pipe equal operator)
- What is a StringIndexOutOfBoundsException? How can I fix it?
- How do popBackStack() and replace() operations differ?
- @ converted to %40 in HTTPPost request
- Unfortunately MyApp has stopped. How can I solve this?
- How to convert any Object to String?
- Unfortunately MyApp has stopped. How can I solve this?
- “Content is not allowed in prolog” when parsing perfectly valid XML on GAE
- Calculating the angle between the line defined by two points
- Android ListView headers
- What is the best/simplest way to read in an XML file in Java application?
- Attempt to invoke virtual method ‘…’ on a null object reference
- Getting java.net.SocketTimeoutException: Connection timed out in android
- This view is not constrained
- Using ADB to capture the screen
- How to use VisibleForTesting for pure JUnit tests
- How to parse JSON boolean value?
- ADK vs JDK vs SDK difference?
- Converting JSON to XML in Java
- Android java.lang.IllegalStateException: Could not execute method of the activity
- How can I fix ‘android.os.NetworkOnMainThreadException’?
- Default keystore file does not exist?
- Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio
- How to print to the console in Android Studio?
- The activity must be exported or contain an intent-filter
- Pause the timer and then continue it
- Variable is accessed within inner class. Needs to be declared final
- Extending from two classes
- ‘Source code does not match the bytecode’ when debugging on a device
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- This Activity already has an action bar supplied by the window decor?
- Cannot resolve symbol “Intent”
- Eclipse error, “The selection cannot be launched, and there are no recent launches”
- RecyclerView onClick
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- Display Animated GIF
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
- Getting warning “NDK is missing a ‘platforms” directory.’ with no NDK
- Converting a string to an integer on Android
- The specified child already has a parent. You must call removeView() on the child’s parent first (Android)
- HTTP Status 500 Error instantiating servlet class
- exposed beyond app through ClipData.Item.getUri
- method does not override method in its superclass
- How to create JSON Object using String?
- Why doesn’t RecyclerView have onItemClickListener()?
- How to read and write XML files?
- How to pass an object from one activity to another on Android
- “Field can be converted to a local variable” message appearing when setting Android ActionBar colour
- Google firebase check if child exists
- equivalent to push() or pop() for arrays?
- How to Get JSON Array Within JSON Object?
- Android For loop
- Android Studio ERROR: Cannot resolve symbol ‘View’
- Aspect Ratio with 800×480
- How to “wait” a Thread in Android
- E/AndroidRuntime﹕ FATAL EXCEPTION: main
- Android Color Picker
- Android – Start service on boot
- Android Emulator: Unfortunately App has stopped
- Sending POST data in Android
- JAVA_HOME is set to an invalid directory:
- why android studio show error of “Missing constraints in constraintlayout”?
- Detecting a long press with Android
- void is an invalid type for this variable
- syntax error: insert } to complete ClassBody
- java.lang.ClassNotFoundException: org.postgresql.Driver, Android
- Eclipse: JVM terminated. Exit code=2
- Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”
- How can I wait for 10 second without locking application UI in android [duplicate]
- Getting a “no interface expected here” when I try to subclass ServiceConnection [duplicate]
- Decompile .smali files on an APK [duplicate]
- Error: The processing instruction target matching “[xX][mM][lL]” is not allowed
- Unable to resolve host “
” No address associated with host name - How can I read a text file in Android?
- How fix Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
- Android: how to create Switch case from this?
- Http status 401 This request requires HTTP authentication (). in tomcat 6
- method does not override or implement a method from a supertype – for Override
- Android Studio 2.2.3: Gradle project sync failed. Basic functionality (e.g. editting, debugging) will not work properly
- set background color: Android
- In Java, how do I parse XML as a String instead of a file?
- set background color: Android
- No content to map due to end-of-input jackson parser
- Initialization of an ArrayList in one line
- Usage of @see in JavaDoc?
- Hadoop “Unable to load native-hadoop library for your platform” warning
- Encrypt Password in Configuration Files?
- Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 0
- Convert boolean to int in Java
- How to convert a String to CharSequence?
- Java error “Value of local variable is not used”