Note that there are some explanatory texts on larger screens.

plurals
  1. POfindViewById(R.id.bAdd) error
    primarykey
    data
    text
    <p>I am trying to learn android app development and I am very much at the beginning.<br> Can some one please tell me what am I doing wrong here?<br> In my MainActivity.java I get errors on add, sub and display (bAdd/bSubb/display cannot be resolved or is not field)</p> <pre><code>public class MainActivity extends Activity { int counter; Button add, sub; TextView display; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); counter = 0; add = (Button) findViewById(R.id.bAdd); sub = (Button) findViewById(R.id.bSub); display = (TextView) findViewById(R.id.tvDisplay); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>activity_main.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Your total is 0" android:textSize="45sp" android:layout_gravity="center" android:gravity="center" android:id="@+id/tvDisplay"/&gt; &lt;Button android:layout-width="250dp" android:layout_height="wrap_content" android:onClick="Add one" android:text="Add one" android:layout_gravity="center" android:textSize="20dp" android:id="@+id/bAdd" /&gt; &lt;Button android:layout-width="250dp" android:layout_height="wrap_content" android:onClick="Add one" android:text="Subtract one" android:layout_gravity="center" android:textSize="20dp" android:id="@+id/bSub" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    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.
 

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