不能在GUI上访问对象 [英] Can't access objects on the GUI

查看:176
本文介绍了不能在GUI上访问对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/2757107/developing-for-android-in-eclipse-r-java-not-generating\">Developing为Android在Eclipse:R.java不会产生


从R.id. *我可以访问txtWeight,txtLength,lblWeight和lblLength,仅此而已。所有其他对象不能从Java code访问。

  TextView的lblAverage =(的TextView)findViewById(R.id.lblAverage);lblAverage不能得到解决或不是字段

这是整个布局文件;

 &LT;的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:填充=4DP&GT;    &LT; ImageView的
        机器人:ID =@ + ID / imageView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =100dp
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:SRC =@绘制/ FTS标识/&GT;    &LT;的TextView
        机器人:ID =@ + ID / lblWeight
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / imageView1
        机器人:layout_below =@ + ID / imageView1
        机器人:layout_marginTop =21dp
        机器人:文字=重量
        机器人:textAppearance =:/&gt;中的Andr​​oid ATTR / textAppearanceLarge?    &LT;的EditText
        机器人:ID =@ + ID / txtWeight
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / lblWeight
        机器人:layout_alignBottom =@ + ID / lblWeight
        机器人:layout_alignParentRight =真
        机器人:EMS =10
        安卓的inputType =numberDecimal/&GT;    &LT;的TextView
        机器人:ID =@ + ID / lblLength
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / lblWeight
        机器人:layout_below =@ + ID / txtWeight
        机器人:layout_marginTop =24dp
        机器人:文字=长度
        机器人:textAppearance =:/&gt;中的Andr​​oid ATTR / textAppearanceLarge?    &LT;的EditText
        机器人:ID =@ + ID / txtLength
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / lblLength
        机器人:layout_alignBottom =@ + ID / lblLength
        机器人:layout_alignLeft =@ + ID / txtWeight
        机器人:EMS =10
        安卓的inputType =numberDecimal/&GT;    &LT;的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / lblLength
        机器人:layout_centerHorizo​​ntal =真
        机器人:ellipsize =无
        机器人:paddingTop =16DP
        机器人:文字=按公斤计算的体重,身长米/&GT;    &LT;按钮
        机器人:ID =@ + ID / btnCalculate
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / textView1
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =16DP
        机器人:paddingLeft =24dp
        机器人:paddingRight =24dp
        机器人:文字=计算
        安卓的onClick =btnCalculate_clicked/&GT;    &LT;的TextView
        机器人:ID =@ + ID / lblBMI
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / btnCalculate
        机器人:layout_centerHorizo​​ntal =真
        机器人:文字=你的体重指数是
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:知名度=隐形/&GT;    &LT;的TextView
        机器人:ID =@ + ID / lblComparedToIndex
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignRight =@ + ID / lblBMI
        机器人:layout_below =@ + ID / lblBMI
        机器人:layout_marginTop =14dp
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:知名度=隐形/&GT;    &LT;按钮
        机器人:ID =@ + ID / btnSubmitToIndex
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / lblComparedToIndex
        机器人:layout_centerHorizo​​ntal =真
        机器人:文字=提交到索引
        机器人:知名度=隐形
        安卓的onClick =btnSubmitToIndex_clicked/&GT;    &LT;的TextView
        机器人:ID =@ + ID / lblAverage
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:文字=平均BMI:?
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium/&GT;&LT; / RelativeLayout的&GT;


解决方案

 我觉得R.java是不正确编译。
再次尝试清洁您的项目并导入ID为您的应用程序包。
我希望它会工作

Possible Duplicate:
Developing for Android in Eclipse: R.java not generating

From R.id.* I can access txtWeight, txtLength, lblWeight and lblLength, and that's it. All the other objects can not be accessed from the Java code.

TextView lblAverage = (TextView) findViewById (R.id.lblAverage);

lblAverage cannot be resolved or is not a field

This is the whole layout file;

<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:padding="4dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/fts  logo" />

    <TextView
        android:id="@+id/lblWeight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="21dp"
        android:text="Weight:"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/txtWeight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/lblWeight"
        android:layout_alignBottom="@+id/lblWeight"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/lblLength"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/lblWeight"
        android:layout_below="@+id/txtWeight"
        android:layout_marginTop="24dp"
        android:text="Length:"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/txtLength"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/lblLength"
        android:layout_alignBottom="@+id/lblLength"
        android:layout_alignLeft="@+id/txtWeight"
        android:ems="10"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lblLength"
        android:layout_centerHorizontal="true"
        android:ellipsize="none"
        android:paddingTop="16dp"
        android:text="Weight in kilograms, length in meters" />

    <Button
        android:id="@+id/btnCalculate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:paddingLeft="24dp"
        android:paddingRight="24dp"
        android:text="Calculate"
        android:onClick="btnCalculate_clicked" />

    <TextView
        android:id="@+id/lblBMI"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnCalculate"
        android:layout_centerHorizontal="true"
        android:text="Your BMI is"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/lblComparedToIndex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/lblBMI"
        android:layout_below="@+id/lblBMI"
        android:layout_marginTop="14dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:visibility="invisible" />

    <Button
        android:id="@+id/btnSubmitToIndex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/lblComparedToIndex"
        android:layout_centerHorizontal="true"
        android:text="Submit to index"
        android:visibility="invisible"
        android:onClick="btnSubmitToIndex_clicked" />

    <TextView
        android:id="@+id/lblAverage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Average BMI: ?"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

解决方案

I think R.java is not compiled correctly.
Try cleaning your project and import id for your application package once again.
I hope it will work 

这篇关于不能在GUI上访问对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆