这个textview有问题吗 为什么一使用就崩溃
生活随笔
收集整理的這篇文章主要介紹了
这个textview有问题吗 为什么一使用就崩溃
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
============問題描述============
??<TextView
????????android:id="@+id/textview1"
????????android:layout_columnSpan="4"
????????android:layout_gravity="fill"
????????android:gravity="right"
????????android:text="0"?/>
public?class?MainActivity?extends?Activity?{
Button?one;
TextView?text1;
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????one=(Button)findViewById(R.id.one);
????????text1=(TextView)findViewById(R.id.textview1);
????????setContentView(R.layout.activity_main);
????}
????public?void?clickone(View?v){
???? double?n=Double.parseDouble(text.getText().toString());
????if(n!=0)
???? text1.setText(text1.getText()+"1");
???? else
???? text1.setText("1");
????
????}
在主函數中各種方法都崩潰
============解決方案1============
one=(Button)findViewById(R.id.one);
?text1=(TextView)findViewById(R.id.textview1);
這兩句放setContentView(R.layout.activity_main);下面試試
轉載于:https://www.cnblogs.com/lianxu61/p/4044479.html
總結
以上是生活随笔為你收集整理的这个textview有问题吗 为什么一使用就崩溃的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Playground
- 下一篇: 信用卡可以用来买保险吗?这些事项要注意!