所以我搜索了很多,但我还没有找到解决方案......因为每个程序都不同。
基本上这个程序的作用是,在edittext字段中输入数字,然后相互乘以,减去和所有好东西。继承我的logcat
05-28 16:37:55.847:I / ActivityManager(274):启动proc xela.kasea.flyffresell以获取活动xela.kasea.flyffresell / .Main:pid = 779 uid = 10046 gids = {50046,1028}
那几乎就是这样的样子,现在我觉得我不需要把清单放在这里,因为我只有一个类(主要)而且那里没有任何错误。注意:拿出包名。
继承我的班级:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class Main extends Activity implements OnClickListener{
EditText perin, amountPrUnit, buy, sell;
ToggleButton lazy;
Button clear, submit, ret;
double ans, subAnswer;
TextView pEarned, tAmount;
int a = Integer.parseInt(perin.getText().toString());
int b = Integer.parseInt(amountPrUnit.getText().toString());
int c = Integer.parseInt(buy.getText().toString());
int d = Integer.parseInt(sell.getText().toString());
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
Log.i("Tag2", "This is my error msg");
initalizer();
lazy.setOnClickListener(this);
clear.setOnClickListener(this);
submit.setOnClickListener(this);
ret.setOnClickListener(this);
/*String a = perin.getText().toString();
String b = amountPrUnit.getText().toString();
String c = buy.getText().toString();
String d = sell.getText().toString(); */
}
private void initalizer() {
// TODO Auto-generated method stub
perin = (EditText) findViewById(R.id.etHowRich);
amountPrUnit = (EditText) findViewById(R.id.etAmountPrUnit);
buy = (EditText) findViewById(R.id.etBuying);
sell = (EditText) findViewById(R.id.etSellingPrUnit);
lazy = (ToggleButton) findViewById(R.id.tbBuying);
clear = (Button) findViewById(R.id.bClear);
submit = (Button) findViewById(R.id.bSubmit);
ret = (Button) findViewById(R.id.bReturn);
pEarned = (TextView) findViewById(R.id.tvEarned);
tAmount = (TextView) findViewById(R.id.tvAmount);
/*int a = Integer.parseInt(perin.getText().toString());
int b = Integer.parseInt(amountPrUnit.getText().toString());
int c = Integer.parseInt(buy.getText().toString());
int d = Integer.parseInt(sell.getText().toString());*/
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bClear:
perin.setText("");
amountPrUnit.setText("");
buy.setText("");
sell.setText("");
lazy.setChecked(false);
break;
case R.id.bReturn:
setContentView(R.layout.display);
break;
case R.id.bSubmit:
pEarned.setText(c*d-(a-(b*c)));
tAmount.setText(c*d+(a-(a-(b*c))));
setContentView(R.layout.finish);
break;
case R.id.tbBuying:
if (lazy.isChecked()){
buy.setText("");
double subAnswer = 0;
int ans = 0;
subAnswer = a/b;
ans = (int) Math.floor(subAnswer);
/*new Integer((int) ans).toString();
Integer.toString(answer);*/
buy.setText(ans);;
}
break;
}
}
}
答案 0 :(得分:1)
请在下面
int a = Integer.parseInt(perin.getText().toString());
int b = Integer.parseInt(amountPrUnit.getText().toString());
int c = Integer.parseInt(buy.getText().toString());
int d = Integer.parseInt(sell.getText().toString());
在initalizer();
之后
您正在尝试在初始化之前使用这些组件......
最后,您的代码应如下所示:
yourcode......
initalizer();
int a = Integer.parseInt(perin.getText().toString());
int b = Integer.parseInt(amountPrUnit.getText().toString());
int c = Integer.parseInt(buy.getText().toString());
int d = Integer.parseInt(sell.getText().toString());
then rest of the code