gpt4 book ai didi

java - android.content.res.Resources$NotFoundException : String resource ID #0x42

转载 作者:行者123 更新时间:2023-12-01 08:53:49 27 4
gpt4 key购买 nike

我有一个 ListView 。当我单击每个项目时,我想显示一个带有编辑文本的警报对话框,然后将输入值保存到整数变量中。但是,它显示错误。当我不转换输入文本时,它工作正常,但当我使用 Integer.parseInt() 时,应用程序崩溃。这是我的代码和 logcat。

//代码

/**
* A simple {@link Fragment} subclass.
*/
public class All extends Fragment {

//EXPERIMENTAL CODE STARTS
private VolleySingleton volleySingleton;
private RequestQueue requestQueue;
private RecyclerView allItemList;
private ArrayList<Items> listItems=new ArrayList<>();
private AdapterItemAll adapterItemAll;
public static int ticketNum=5;
DatabaseHelper myDb;
public int quantity=0;
public float totalPrice=0;
private String title;
private boolean update;
private String name;

String strQuantity;

EditText quantityInput;


//SETTING IMAGE TEST CODE STARTS





//public static final String URL_API="http://www.delaroystudios.com/images/teams.json";

//ENDS
public All() {
// Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_all, container, false);

// allItemList=(RecyclerView) view.findViewById(R.id.allItemsList);
// allItemList.setLayoutManager(new LinearLayoutManager(getActivity()));
// adapterItemAll=new AdapterItemAll(getActivity());
// allItemList.setAdapter(adapterItemAll);




//****LISTVIEW EXPERIMENT STARTS
ListView listView=(ListView) view.findViewById(R.id.allItemsList);
myDb=new DatabaseHelper(getContext());

ArrayList<String> theList=new ArrayList<>();
final Cursor data=myDb.getItemContents();

if(data.getCount()==0){
Toast.makeText(getActivity(),"List is Empty",Toast.LENGTH_SHORT).show();
}else{
while(data.moveToNext()){
theList.add(0,data.getString(1));

ListAdapter listAdapter=new ArrayAdapter<>(getActivity(),android.R.layout.simple_list_item_1,theList);
listView.setAdapter(listAdapter );
}
}




//LIST ITEM ONCLICK ADD QUANTITY TO TICKET STARTS
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
name = (String) parent.getItemAtPosition(position);


//ALERT DECLARE

AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
builder.setTitle("Item Quantity");
builder.setIcon(R.mipmap.ic_receipt_black_24dp);
builder.setMessage("Enter Item Quantity");

quantityInput=new EditText(getContext());
builder.setView(quantityInput);
//SET POSITIVE

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {


strQuantity = quantityInput.getText().toString();
quantity=Integer.valueOf(strQuantity);

Toast.makeText(getActivity(),quantity,Toast.LENGTH_LONG).show();

Toast.makeText(getActivity(),"Enter the correct quantity",Toast.LENGTH_LONG).show();

}
});


AlertDialog ad=builder.create();
ad.show();
//ENDS


//updating quantity
update=myDb.updateTicketQuantity(name,quantity);


Toast.makeText(getActivity(),"Total "+quantity+ "Items Added to the Ticket",Toast.LENGTH_LONG).show();

}
});
//ENDS

//LISTVIEW EXPERIMENT ENDS




return view;
}


public int quantityIncrease(int quantity){

this.quantity=quantity+1;
int qt=this.quantity;

return qt;

}

}

//错误日志

E/AndroidRuntime: FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: String resource ID #0x42
at android.content.res.Resources.getText(Resources.java:230)
at android.widget.Toast.makeText(Toast.java:265)
at com.soumya.possystem.All$1$1.onClick(All.java:142)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

试试这个:

 builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {


strQuantity = quantityInput.getText().toString();

quantity= Integer.parseInt(strQuantity); //int

Toast.makeText(getActivity(),String.valueOf(quantity),Toast.LENGTH_LONG).show(); //error here

Toast.makeText(getActivity(),"Enter the correct quantity",Toast.LENGTH_LONG).show();

}
});

关于java - android.content.res.Resources$NotFoundException : String resource ID #0x42,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42186346/

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