android开发中的问题,出现unfortunately ,xxxhas stopped,怎么解决啊???高手啊!!!!! 10
packagexue.lang;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view...
package xue.lang;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
public class Wang6Activity extends Activity implements OnClickListener
{
private EditText P2, V1, V2, d;
TextView text;
// double P1;//上游压力
// double P2;//下游压力
// double V1;//上游流速
// double V2;//下游流速
// double d;//密度
private Button Calculate;
private double p1, p2, v1, v2, D;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView )this.findViewById(R.id.text);
P2 = (EditText)this. findViewById(R.id.etP2);
V1 = (EditText) this.findViewById(R.id.etV1);
V2 = (EditText) this.findViewById(R.id.etV2);
d = (EditText) this.findViewById(R.id.etd);
v1 = Double.parseDouble(V1.getText().toString());
v2 = Double.parseDouble(V2.getText().toString());
p2 = Double.parseDouble(P2.getText().toString());
D= Double.parseDouble(d.getText().toString());
Calculate = (Button)this.findViewById(R.id.Calculate);
text.setTextSize(18);
Calculate.setOnClickListener(this);
}
public void onClick(View v) {
if (v == Calculate){
System.out.println("");
p1= (v2 * v2 - v1 * v1) / (2 * 9.8) + p2 /( 9.8 * D);
text.setText( "计算结果是");
}
}
} 展开
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
public class Wang6Activity extends Activity implements OnClickListener
{
private EditText P2, V1, V2, d;
TextView text;
// double P1;//上游压力
// double P2;//下游压力
// double V1;//上游流速
// double V2;//下游流速
// double d;//密度
private Button Calculate;
private double p1, p2, v1, v2, D;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView )this.findViewById(R.id.text);
P2 = (EditText)this. findViewById(R.id.etP2);
V1 = (EditText) this.findViewById(R.id.etV1);
V2 = (EditText) this.findViewById(R.id.etV2);
d = (EditText) this.findViewById(R.id.etd);
v1 = Double.parseDouble(V1.getText().toString());
v2 = Double.parseDouble(V2.getText().toString());
p2 = Double.parseDouble(P2.getText().toString());
D= Double.parseDouble(d.getText().toString());
Calculate = (Button)this.findViewById(R.id.Calculate);
text.setTextSize(18);
Calculate.setOnClickListener(this);
}
public void onClick(View v) {
if (v == Calculate){
System.out.println("");
p1= (v2 * v2 - v1 * v1) / (2 * 9.8) + p2 /( 9.8 * D);
text.setText( "计算结果是");
}
}
} 展开
2个回答
展开全部
v1 = Double.parseDouble(V1.getText().toString());
v2 = Double.parseDouble(V2.getText().toString());
p2 = Double.parseDouble(P2.getText().toString());
D= Double.parseDouble(d.getText().toString());
这个输入的text不应该在 onCreate 的时候获取,最好放在 Calculate的onClick事件中获取输入的信息。还有转换类型如果不对也会抛出异常,使程序终止
v2 = Double.parseDouble(V2.getText().toString());
p2 = Double.parseDouble(P2.getText().toString());
D= Double.parseDouble(d.getText().toString());
这个输入的text不应该在 onCreate 的时候获取,最好放在 Calculate的onClick事件中获取输入的信息。还有转换类型如果不对也会抛出异常,使程序终止
追问
log.cat 中显示
p2 = Double.parseDouble(P2.getText().toString());
有问题,不知道怎么回事?
追答
这几句 获取参数的都放进 下面的 onClick 中。
public void onClick(View v) {
if (v == Calculate){
System.out.println("");
v1 = Double.parseDouble(V1.getText().toString());
v2 = Double.parseDouble(V2.getText().toString());
p2 = Double.parseDouble(P2.getText().toString());
D= Double.parseDouble(d.getText().toString());
p1= (v2 * v2 - v1 * v1) / (2 * 9.8) + p2 /( 9.8 * D);
text.setText( "计算结果是");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询