JAVA在Android输出字符串,java – 在android中将字符串转换为bigdecimal

嗨我怎么能在

android中将字符串转换为bigdecimal.

这是我的第一项活动:

public class ViewCartActivity extends Activity {

String mGrandTotal;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.viewcartactivity);

ListView mLstView1 = (ListView) findViewById(R.id.listView1);

TextView mTxtViewGrandTotal = (TextView) findViewById(R.id.mTxtViewGrandTotalValue);

Button mBtnSubmit = (Button) findViewById(R.id.mBtnSubmit);

ViewCartAdapter mViewCartAdpt = new ViewCartAdapter(

ViewCartActivity.this);

mLstView1.setAdapter(mViewCartAdpt);

if (Constants.mItem_Detail.size() > 0) {

Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0)

.get(SingleMenuItem.KEY_TOTAL));

for (int i = 1; i < Constants.mItem_Detail.size(); i++) {

mGTotal = mGTotal

+ Double.parseDouble(Constants.mItem_Detail.get(i).get(

SingleMenuItem.KEY_TOTAL));

}

mGrandTotal = String.valueOf(mGTotal);

mTxtViewGrandTotal.setText("$" + mGrandTotal);

}

mBtnSubmit.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent i = new Intent(getApplicationContext(),CustomerLogin.class);

i.putExtra("GrandTotal",mGrandTotal);

startActivity(i);

}

CustomerLogin.java(下一个活动):

String mGrandTotal;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.customer_login);

Bundle b = getIntent().getExtras();

String total = b.getString("GrandTotal");

-----

------

if(isUserValidated && isPasswordValidated)

{

String s= getIntent().getStringExtra(mGrandTotal);

Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);

intent.putExtra(mGrandTotal,s);

startActivity(intent);

}

PayPalIntegrationActivity.java(第3个活动)如下所示:

public class PayPalIntegrationActivity extends Activity implements OnClickListener {

String mGrandTotal;

private PayPal mPayPal;

private CheckoutButton launchPayPalButton;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_pay_pal_integration);

-------

------

@Override

public void onClick(View v) {

payWithPaypal();

}

private PayPalPayment payWithPaypal() {

PayPalPayment newPayment = new PayPalPayment();

Intent in = getIntent();

String total = in.getStringExtra(mGrandTotal);

BigDecimal sPrice = new BigDecimal(total);

newPayment.setSubtotal(sPrice);

newPayment.setCurrencyType(Currency.getInstance(Locale.US));

我必须将grandtotal值传递给我的paypalintegration活动.

但我的控制台窗口显示以下错误:

12-21 05:52:09.571: E/AndroidRuntime(782): FATAL EXCEPTION: main

12-21 05:52:09.571: E/AndroidRuntime(782): java.lang.NullPointerException

12-21 05:52:09.571: E/AndroidRuntime(782): at java.math.BigDecimal.(BigDecimal.java:483)

12-21 05:52:09.571: E/AndroidRuntime(782): at com.ssmobileproductions.catalogue.PayPalIntegrationActivity.payWithPaypal(PayPalIntegrationActivity.java:74)

12-21 05:52:09.571: E/AndroidRuntime(782): at com.ssmobileproductions.catalogue.PayPalIntegrationActivity.onClick(PayPalIntegrationActivity.java:66)

12-21 05:52:09.571: E/AndroidRuntime(782): at android.view.View.performClick(View.java:2408)

请帮帮我.我的代码中有错误.

我希望需要o / p是:

mGrandTotal值从我的第一个活动传递到最后一个活动(paypalintegration活动)

mGrandTotal值设置为以下行:newPayment.setSubtotal(sPrice);

我该怎么办.请告诉我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值