I am getting an error where it says "Error:(52, 1) error: class, interface, or enum expected" I am trying to make it so that when the button is clicked it sends a message in xml to open another activity. this is my xml code for the button
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Period 1"
android:id="@+id/button"
android:clickable="true"
android:elegantTextHeight="false"
android:textSize="50sp"
android:paddingStart="80dp"
android:layout_marginTop="50dp"
android:background="#33cbff"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:enabled="true"
android:layout_alignParentStart="true"
android:onClick="sendMessage"
android:paddingEnd="80dp" /><![CDATA[
/>
and this is the java in the main activity that is being underlined in red.
public void sendMessage(View view){
Intent intent = new Intent(MainActivity.this, Period1.class);
startActivity(intent);
}
it is the "MainActivity.this, Period1.class" that is underlined in red Period1 is the new activity I want to open
After seeing the above posted code, I guess you might have written the sendMessage method outside your MainActivity class. If so please write that function inside the MainActivity class declaration.
public class MainActivity extends Activity {
// Your code
public void sendMessage(View view) {
Intent intent = new Intent(MainActivity.this, Period1.class);
startActivity(intent);
}
}
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.