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

int in TextView not working

rasen58

Lurker
Hi, in my app, when ever I press the button, it keeps crashing.

What it is supposed to do is when they press the button, an int is incremented and displayed on the screen.

MainActivity.java
Code:
package com.example.myfirstapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	public final static String  EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
	public int mult = 1;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    /** Called when the user clicks on the Send button */
    public void sendMessage(View view)
    {
    	//Intent intent = new Intent(this, DisplayMessageActivity.class);
    	
    	TextView val = (TextView) findViewById(R.id.val);
    	val.setText(mult);
    	mult+=1;

    	//EditText editText = (EditText) findViewById(R.id.edit_message);
    	//String message = editText.getText().toString();
    	//intent.putExtra(EXTRA_MESSAGE, message);
    	//startActivity(intent);
    }
}

activity_main.xml
HTML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="sendMessage"
        android:text="@string/button_send" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/text"
        android:textSize="30sp"
        tools:context=".DisplayMessageActivity" />
    
    <TextView
        android:id="@+id/val"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="37dp"
        android:text="            " />

</RelativeLayout>

<string name="text"> I Love pie</string>
 
Back
Top Bottom