Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid App crashing on setText
    text
    copied!<p>I am new to android development and my code is not working how it should. The following does not update the text I have in a string called otp1. I think it is firing the exception, is there a way to see if it is? Also, any tips on why it is not working would be great.</p> <pre><code>package com.josephflynn.HelloWorld; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { final TextView textViewToChange = (TextView) findViewById(R.string.otp1); textViewToChange.setText("otp"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>This is my main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/otp1" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is my first Android Application!" /&gt; &lt;Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Add this clickable button!" /&gt; &lt;/LinearLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload