[英]Error: Cannot find symbol variable when trying to establish imageviews
所以我在我的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?
檢查您的Xml文件,並確保它們已正確關閉/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.