我正在编写一个程序,我试图在ProductInformationActivity.java中打开该特定项目,我点击了ListView项目行, 但每当我点击Item Row时,我都会不幸的是App已停止
错误:由以下引起:java.lang.NumberFormatException:无效的double:“”
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
答案 0 :(得分:0)
嗯,您需要将产品项目打包到Intent
的捆绑包中,但这意味着您的产品类应该实现Serializable
(使用putSerializable()
)或{{1但是你可以使用一种更简单的方法 - 在你的Parcelable
中创建public static
类型的Product
字段,你需要做的就是在实例化它之前调用ProductInformationActivity
,那就是全部。像
ProductInformationActivity
答案 1 :(得分: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;
}