我的应用程序在读取XML对象之前工作正常,但现在我已经添加到两个按钮和textview,它找不到它们。
所以我在那里添加了三个对象以便更好地控制我的应用程序,而活动类找不到它们
public class TVListingTestActivity extends Activity implements OnClickListener
{
private static final String TAG = "myApp";
private EditText infoView;
private String result;
private String full;
public int count;
final Context context =this;
private LinkedList<Widget> aList;
private LinkedList<String> stringList;
private LinkedList<Button> buttons;
private Button forwardDay;
private Button backDay;
private TextView display;
private int dayParse= 0;
private String tvListingURL;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
stringList = new LinkedList<String>();
infoView= (EditText) findViewById(R.id.infoView);
tvListingURL = "http://bleb.org/tv/data/rss.php?ch=bbc1_scotland&day="+dayParse;
forwardDay=(Button)findViewById(R.id.forwardbutton);
backDay=(Button)findViewById(R.id.backbutton);
display=(TextView)findViewById(R.id.displayview);
资源似乎出现在R文件中,所以我无法理解问题所在。以前有没有人遇到这样的事情?
package org.me.myandroidstuff;
public final class R {
public static final class array {
public static final int shows=0x7f040000;
}
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int back=0x7f060002;
public static final int cspinner=0x7f060007;
public static final int dialog_info=0x7f060000;
public static final int infoView=0x7f060003;
public static final int main=0x7f060004;
public static final int main_page=0x7f060006;
public static final int mainll=0x7f060005;
public static final int reminder=0x7f060001;
}
public static final class layout {
public static final int dialog_info=0x7f030000;
public static final int main=0x7f030001;
public static final int main_page=0x7f030002;
}
public static final class string {
public static final int app_name=0x7f050001;
public static final int hello=0x7f050000;
}
}
答案 0 :(得分:1)
从java文件中的导入中删除android.R
。
答案 1 :(得分:0)
检查R.java是否在布局类中包含“main”类。 R.java位于gen文件夹中。
答案 2 :(得分:0)
两个按钮的ID和R.java中的TextView不是TVListingTestActivity类中的ID。确保它们在XML布局文件和R.java中相同,清理项目,然后正确初始化:
例如,应该从以下位置更改backDay按钮初始化:
backDay = (Button)findViewById(R.id.backbutton);
为:
backDay = (Button)findViewById(R.id.back);