gpt4 book ai didi

java - 运算符 != 未定义参数类型 long、null

转载 作者:太空狗 更新时间:2023-10-29 16:39:05 26 4
gpt4 key购买 nike

我是初学者 android 开发人员,这是我的第一个项目。我应该将所选数据从 ViewData.java 上的 ListView 显示到 EntryTO.java 上的 ListView。首先,我得到一个错误 nullPointerException。我尝试检测 if 函数的问题在哪里。并且出现该错误。 “运算符 != 对于参数类型 long,null 是未定义的”

这是我尝试从 listview ViewData.java 获取数据时的代码

ListView lv = (ListView) findViewById(android.R.id.list);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(final AdapterView<?> adapter, View v, int pos, final long id) {
final Dialog dialog = new Dialog(ViewData.this);
dialog.setContentView(R.layout.dialog_view);
dialog.setTitle("Masukkan Qty");
dialog.show();
final product b = (product) getListAdapter().getItem(pos);
edtqty = (EditText) dialog.findViewById(R.id.edtqty);
buttonok = (Button) dialog.findViewById(R.id.buttonok);
buttonok.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
switchToEdit(b.getId());
Toast.makeText(ViewData.this, "Ambil product\n"+ b.getId() +"\n"+ b.getname() +"\n"+ b.getbrand()
+ edtqty.getText().toString(), Toast.LENGTH_LONG).show();
dialog.dismiss();
};
});
}
});
public void switchToEdit(long id){
product b = dataSource.getproduct(id);
Intent i = new Intent(this, EntryTO.class);
Bundle bun = new Bundle();

bun.putLong("id", b.getId());
bun.putString("brand", b.getbrand());
bun.putString("qty",edtqty.getText().toString());
i.putExtras(bun);
finale();
startActivity(i);
}

这是当我尝试将所选数据从 ListView ViewData.java 显示到 EntryTO.java 上的另一个 ListView 时的代码

      Bundle bun = null;
if(bun.getLong("id")!=null && bun.getString("brand")!=null && bun.getString("qty")!=null)
{ bun = EntryTO.this.getIntent().getExtras();
id = bun.getLong("id");
brand = bun.getString("brand");
qty = bun.getString("qty");

String[]array ={brand,qty};

adapter = new ArrayAdapter<String>(EntryTO.this,
R.layout.item_list,R.id.edtnama, array);
setListAdapter(adapter);
}

请帮帮我。

最佳答案

您可以使用 Long 参数。像这样:

if( bun.getLong("id") != 0L)

关于java - 运算符 != 未定义参数类型 long、null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21152976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com