Note that there are some explanatory texts on larger screens.

plurals
  1. POid cannot be resolved or is not a field, Button listener
    text
    copied!<p>I'm pretty sure i'm missing something really easy here... I'm new to android so i'm sorry about this. I think i'm not linking the buttons to the listener properly, basicly what I think i'm doing is making a listner (for buttons) and checking which button has been pushed,</p> <h1>MainMenu.java</h1> <pre><code>package com.coursework; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; public class mainMenu extends Activity{ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.mainmenu); TextView txt = (TextView) findViewById(R.id.gameName); Typeface font = Typeface.createFromAsset(getAssets(), "RetroElectro.ttf"); txt.setTypeface(font); Button.OnClickListener listener = new Button.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub if(v.id == R.id.play){ Log.w("Test","one"); } else if(v.id == R.id.options){ Log.w("Test","one"); } } }; ((Button)findViewById(R.id.play)).setOnClickListener(listener); </code></pre> <p>} }</p> <h1>XML</h1> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/gameName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/gameName" android:layout_centerHorizontal="true" android:gravity="center" android:layout_marginTop="20dp" android:textSize="80sp" /&gt; &lt;Button android:layout_width="@dimen/button" android:id="@+id/play" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="120dp" android:text="@string/play"&gt;&lt;/Button&gt; &lt;Button android:layout_width="@dimen/button" android:id="@+id/options" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/play" android:text="@string/options"&gt;&lt;/Button&gt; &lt;Button android:layout_width="@dimen/button" android:id="@+id/scoreboard" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/options" android:text="@string/score"&gt;&lt;/Button&gt; &lt;Button android:layout_width="@dimen/button" android:id="@+id/exit" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/scoreboard" android:text="@string/exit"&gt;&lt;/Button&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The part which is the problem is the line <code>if(v.id == R.id.play){</code> and <code>if(v.id == R.id.play){</code> with an error,</p> <p><code>id cannot be resolved or is not a field</code></p>
 

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