• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps HELP APP CRashes

Hi Please Help Me Because this is My First Time Making Android Application

Heres What Im Trying to do here..
Theres Two Major Component In my Application
1.) TextView - which the text set to "Greetings Appear Here"
2.)Button

When i click the button the TextView text should change to "Hello"
but suddenly my app crashes Please Help Here is My code

Java Class FIle
package renz.com.myfirstapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
TextView message;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
message=(TextView)findViewById(R.id.greetings_view);
}

public void showGreetings()
{
String mes="Hello";
message.setText(mes);
}
}

XML FIle
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="renz.com.myfirstapp.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greeetings Appear Here"
android:id="@+id/greetings_view" />

<Button
android:text="Show Greetings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/greetings_view"
android:onClick="showGreetings"
/>
</RelativeLayout>
 

Attachments

  • prob.png
    prob.png
    10.2 KB · Views: 94
Hi. Can you please show the stack trace from your Logcat view.
Also include all the code, including the Button click listener method.
 
Back
Top Bottom