Note that there are some explanatory texts on larger screens.

plurals
  1. POApp shutdown when testing on AVD
    primarykey
    data
    text
    <p>i'm trying to learn Android and i'm doing a simple exercise involving two buttons and a textview. However when I try to run the app in the emaulator, the app is forced to shutdown.</p> <p>Below is the code:</p> <pre><code>public class CambiarColorActivity extends Activity implements View.OnClickListener { Button btnRed; Button btnBlue; TextView text; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); TextView text = (TextView)findViewById(R.id.textView1); btnRed=(Button)findViewById(R.id.button1); btnBlue=(Button)findViewById(R.id.button2); btnRed.setOnClickListener(this); btnBlue.setOnClickListener(this); } public void onClick(View view) { changeColor(); } private void changeColor() { if(btnRed.isPressed()) { text.setBackgroundResource(Color.RED); } else { text.setBackgroundResource(Color.BLUE); } } } </code></pre> <p>And these are the errors I found in the log in Eclipse:</p> <pre><code>11-04 11:34:42.377: E/AndroidRuntime(376): Caused by: java.lang.NullPointerException 11-04 11:34:42.377: E/AndroidRuntime(376): at mi.entrenamiento.OrejanoX.CambiarColorActivity.onCreate(CambiarColorActivity.java:25) </code></pre> <p>Here is my part of my main.xml</p> <pre><code>&lt;LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/button1" style="@style/red" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableLeft="@drawable/red" android:text="@string/red" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableLeft="@drawable/blue" android:text="@string/azul" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any help will be welcome.</p> <p>Thanks and Regards, Mauro.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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