setText()方法在我的应用程序中返回null为什么?
public class GetValue extends Activity { char letter = 'g'; int ascii = letter; /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); TextVIEw textVIEw = (TextVIEw)findVIEwByID(R.ID.txt_1); textVIEw.setText(ascii); }}
无论我输入什么文字都无关紧要,无论如何它都会崩溃.为什么setText()继续返回null?
先感谢您
解决方案:我的错误是在xml文件中.我写:
androID:text =“@ ID / txt_1”
什么时候应该说:
androID:ID =“@ ID / txt_1”
非常感谢所有的答案和评论!
解决方法:
您尝试将整数作为参数传递给setText,后者假定它是资源ID.要显示计算文本,请将其作为字符串传递:textVIEw.setText(“g”);
编辑:检查你的XML文件,我测试了一些非常基本的东西,它的工作原理
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="@R_502_6822@://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"> <TextVIEw androID:ID="@+ID/txt_1" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:text="myTextVIEw"/></linearLayout>
也许尝试清理你的项目(Project-> Eclipse中的Clean),我最近在最后一个ADT版本上遇到了R代的问题.
总结以上是内存溢出为你收集整理的android – textView.setText();崩溃全部内容,希望文章能够帮你解决android – textView.setText();崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)