完全错误
FATAL EXCEPTION: main
Process: com.intent.explicitintent, PID: 9871
java.lang.NumberFormatException: For input string: "android.support.v7.widget.AppCompatEditText{c41d17d VFED..CL. ........ 80,80-400,148 #7f0d0075 app:id/numberOne}"
at java.lang.Integer.parseInt(Integer.java:521)
at java.lang.Integer.parseInt(Integer.java:556)
at com.intent.explicitintent.MainActivity.add(MainActivity.java:40)
at com.intent.explicitintent.MainActivity$1.onClick(MainActivity.java:28)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
我想添加简单的添加。但它不起作用。 我有两个EditText字段和一个Button。我希望在TextView
中单击按钮时,结果显示在另一个活动中这是我的代码
活动一。
public class MainActivity extends AppCompatActivity {
EditText oneNumber;
EditText secondNumber;
Button button;
int e;
int b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
oneNumber = (EditText) findViewById(R.id.numberOne);
secondNumber = (EditText) findViewById(R.id.numberTwo);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
add(v);
}
});
}
public void add(View view) {
int a = Integer.parseInt(String.valueOf(oneNumber));
int b = Integer.parseInt(String.valueOf(secondNumber));
int result = a + b;
Intent intent = new Intent();
intent.putExtra("add", result);
intent.setClass(MainActivity.this, AnotherActivity.class);
startActivity(intent);
}
}
第二项活动
public class AnotherActivity extends AppCompatActivity {
TextView total;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_another);
total = (TextView) findViewById(R.id.Total);
Bundle extras = getIntent().getExtras();
String result = extras.toString();
total.setText(result);
}
}
我想我从EditText获取整数并在另一个活动中将结果导入textView
任何帮助?
答案 0 :(得分:2)
问题在这里:
SELECT LeaseTenantSSN
FROM tenants
GROUP BY LeaseTenantSSN
HAVING COUNT(DISTINCT houseid) = 3
它应该是:
int a = Integer.parseInt(String.valueOf(oneNumber));
int b = Integer.parseInt(String.valueOf(secondNumber));
int a = Integer.parseInt(oneNumber.getText().toString());
int b = Integer.parseInt(secondNumber.getText().toString());
是oneNumber
。你需要从中获取字符串
在您的第二项活动中,使用以下方式获取结果:
Editext
答案 1 :(得分:1)
String.valueOf(oneNumber)
与oneNumber.toString()
基本相同,(我相信你已经弄清楚了)与方框内的文字不同。
也许您的意思是使用oneNumber.getText().toString()
代替。