android 新人仿照视频写的一个计算的Demo 对比几次没问题,但是执行 报错求救

Activity03.java

 private EditText Ac03textone;
    private EditText Ac03texttwo;
    private TextView Ac03viewone;
    private Button Ac03buttone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity03);

        Ac03textone = (EditText) findViewById(R.id.ETextone);
        Ac03texttwo = (EditText) findViewById(R.id.ETexttwo);
        Ac03buttone = (Button) findViewById(R.id.Bttone);
        Ac03viewone = (TextView) findViewById(R.id.TView);
        // 设置显示值
        // symbol.setext("乘以")
        Ac03viewone.setText(R.string.chengyi);
        Ac03buttone.setText(R.string.jisuan);
        // 按钮绑定监听
        Ac03buttone.setOnClickListener(new CalculteListenter());
    }

    class CalculteListenter implements OnClickListener {

        @Override
        public void onClick(View v) {
            // TODO 自动生成的方法存根
            // 取得两个text的值
            String Ac03textstr1 = Ac03textone.getText().toString();
            String Ac03textstr2 = Ac03texttwo.getText().toString();

            Intent intent = new Intent();
            intent.putExtra("one", Ac03textstr1);
            intent.putExtra("two", Ac03textstr2);
            intent.setClass(Activity03.this, Activity03_1.class);
            // 使用intent对象启动 activity03_1
            Activity03.this.startActivity(intent);
        }

    }

Activity03_1.java

 public class Activity03_1 extends Activity {


    private TextView jieguo;


    protected void onCreate(Bundle saveIntanceState){

        super.onCreate(saveIntanceState);
        setContentView(R.layout.activity03_2);

        jieguo = (TextView) findViewById(R.id.AC2_t1);


        Intent intent=getIntent();
        String ac2_str1=intent.getStringExtra("one");
        String ac2_str2=intent.getStringExtra("two");


        int  ac2_int1=Integer.parseInt(ac2_str1);
        int ac2_int2=Integer.parseInt(ac2_str2);
        int jg=ac2_int1 * ac2_int2;
        jieguo.setText(jg);

    }

activity_Activity03.xml

  <Button
        android:id="@+id/Bttone"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true" />

    <EditText
        android:id="@+id/ETexttwo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/Bttone"
        android:layout_alignLeft="@+id/Bttone"
        android:layout_marginBottom="30dp"
        android:ems="10" />

    <TextView
        android:id="@+id/TView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/ETexttwo"
        android:layout_alignLeft="@+id/ETexttwo"/>

        <EditText
            android:id="@+id/ETextone"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/TView"
            android:layout_alignLeft="@+id/TView"
            android:layout_marginBottom="27dp"
           />

Activity03_2.xml

    <TextView
        android:id="@+id/AC2_t1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

Strings.xml

 <?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">activity_3</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="chengyi">乘以</string>
    <string name="jisuan">计算</string>
    <string name="about">关于</string>
    <string name="exit">退出</string>

</resources>

一点击计算按钮就报错,新人有点愚笨,求牛人给看眼

2个回答

原因是jieguo.setText(jg);,setText参数是字符串,在你的程序里传进去了整数,改成

jieguo.setText("" + jg);

或者

jieguo.setText(String.valueOf(jg));

Activity03_1 这个类有没有去AndroidManifest.xml中设置。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问