1

我正在编写一个程序,我试图在其中打开 ProductInformationActivity.java 中的那个特定项目,我点击了 ListView Item Row,但是每当我点击 Item Row 时,我就会不幸 App has Stopped

错误:引起:java.lang.NumberFormatException:无效双:“”

CartAdapter.java:

    public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.listrow_cart, null);
        vi.setClickable(true);
        vi.setFocusable(true);
        vi.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) 
        {               
            HashMap<String, String> prod = Constants.mItem_Detail.get(position);
            Intent mViewCartIntent = new Intent
                    (activity,com.era.restaurant.versionoct.menu.ProductInformationActivity.class);             
            mViewCartIntent.putExtra("product", prod);
            activity.startActivity(mViewCartIntent);                
        }
    });

Logcat 说:

      04-27 04:25:01.520: E/AndroidRuntime(1214): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.era.restaurant.versionoct/com.era.restaurant.versionoct.menu.ProductInformationActivity}: java.lang.NumberFormatException: Invalid double: ""
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.os.Looper.loop(Looper.java:137)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at java.lang.reflect.Method.invokeNative(Native Method)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at java.lang.reflect.Method.invoke(Method.java:511)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at dalvik.system.NativeStart.main(Native Method)
04-27 04:25:01.520: E/AndroidRuntime(1214): Caused by: java.lang.NumberFormatException: Invalid double: ""
04-27 04:25:01.520: E/AndroidRuntime(1214):     at java.lang.StringToReal.invalidReal(StringToReal.java:63)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at java.lang.StringToReal.parseDouble(StringToReal.java:248)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at java.lang.Double.parseDouble(Double.java:295)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at com.era.restaurant.versionoct.menu.ProductInformationActivity.onCreate(ProductInformationActivity.java:77)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.Activity.performCreate(Activity.java:5104)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-27 04:25:01.520: E/AndroidRuntime(1214):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-27 04:25:01.520: E/AndroidRuntime(1214):     ... 11 more
4

2 回答 2

0

好吧,例如,您需要将产品项目打包到Intent's 包中,但这意味着您的产品类应该实现Serializable(使用putSerializable())或Parcelable.
但是您可以使用更简单的方法 -在您的中创建public static类型字段,您需要做的只是在调用之前实例化它,仅此而已。喜欢ProductProductInformationActivityProductInformationActivity

        @Override
            public void onClick(View v) 
            {               
                HashMap<String, String> product = new HashMap<String, String>();
                ProductInformationActivity.product = Constant.wishproducts.get(position);
                // startActivity(new Intent(getBaseContext(),ProductInformationActivity.class));
                Intent mViewCartIntent = new Intent(activity,ProductInformationActivity.class);
                activity.startActivity(mViewCartIntent);                                                           
            }
于 2013-04-26T12:41:49.690 回答
0
CartActivity {


    //...

    private void initView() {
        //...
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> av, View v, int pos, long id)
            {
                final HashMap<String, String> prod = Constant.wishproducts.get(pos);
                final Intent viewCartIntent = new Intent(CartActivity.this, ProductInformationActivity.class);
                viewCarIntent.putExtra("product", prod);
                startActivity(viewCartIntent);
            }
        });
    }

}

适配器

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.listrow_cart, null);
    }
    //assign text, images, etc
    return vi;
}
于 2013-04-26T12:45:42.667 回答