所以我的xml文件中有一个ImageView,它是我创建的图像。它的id是gameplayTop。在我的该活动的java文件中,我尝试设置一个变量来设置imageview,但是当我启动我的模拟器时它会显示“错误:找不到符号变量gameTop”。
这是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.ics466.brainscrew.GameplayActivity"
android:background="@color/background">
<Chronometer
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/chronometer"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gameplay_Area"
android:src="@drawable/playarea"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="100dp"
android:layout_height="250dp"
android:id="@+id/gameLeft"
android:src="@drawable/gameplay_left_blue"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="250dp"
android:layout_height="100dp"
android:id="@+id/gameTop"
android:src="@drawable/gameplay_top_blue"
android:maxWidth="250dp"
android:maxHeight="95dp"
android:layout_marginTop="120dp"
android:layout_below="@+id/chronometer"
android:layout_centerHorizontal="true"
android:layout_gravity="right" />
</RelativeLayout>
这是我的javacode(剪掉了东西,但主要是关注我的imageview)
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class GameplayActivity extends AppCompatActivity {
ImageView top, bot, left, right;
String message;
private android.widget.RelativeLayout.LayoutParams layoutParams;
/**
* Sets the screen layout and sets this screen to fullscreen-mode.
*
* @param savedInstanceState saved previous state.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gameplay);
top = (ImageView) findViewById(R.id.gameTop);
Random rnd = new Random(2);
int colorIndex = rnd.nextInt(8);
makeBorders(rand4());
}
我是否需要做其他事情让它识别id?
答案 0 :(得分:0)
检查您的Xml文件,并确保它们已正确关闭/&gt;