Java – resource exception not found
•
Java
I got a resource not found exception in the line where I referenced one of my class methods that mapped the EditText object I don't understand why I have this problem
I have a store Java is a simple java class, which just maps the data from the spinner and EditText And one called spinpizza Java classes for printing their values
Store. java
package com.Lak; import android.os.Parcel; import android.os.Parcelable; public class store implements Parcelable { @SuppressWarnings("rawtypes") public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public store createFromParcel(Parcel in) { return new store(in); } public store[] newArray(int size) { return new store[size]; } }; private static final long serialVersionUID = 1L; private String pizzaname; private String pizzasize; private int n; public store() { } public store(Parcel source) { /* * Reconstruct from the Parcel */ n = source.readInt(); pizzaname = source.readString(); pizzasize = source.readString(); } public void setOrder(String name,String size,int qty) { pizzaname = name; pizzasize = size; n = qty; } public String getPizzaName() { return pizzaname; } public int getQuantity() { return n; } public String getPizzaSize() { return pizzasize; } public int describeContents() { return 0; } public void writeToParcel(Parcel dest,int flags) { dest.writeInt(n); dest.writeString(pizzaname); dest.writeString(pizzasize); } /** Called when the activity is first created. */ }
SpinPizza. java
package com.Lak; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; public class SpinPizza extends Activity { private static final long serialVersionUID = 1L; store B[] = new store[10]; int n,i,num; Spinner s = null,s1 = null; EditText edittext = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drop); s = (Spinner) findViewById(R.id.spinner); ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this,R.array.pizzaarray,android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(adapter); s1 = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<?> adapter1 = ArrayAdapter.createFromResource(this,R.array.sizearray,android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s1.setAdapter(adapter1); edittext = (EditText) findViewById(R.id.edittext); i = 0; edittext.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v,int keyCode,KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER)) { // Perform action on key press B[i] = new store(); //n=Integer.parseInt(edittext.getText().toString()); // num = Float.valueOf(edittext.getText().toString()); try { num = Integer.parseInt(edittext.getText().toString()); } catch (NumberFormatException nfe) { System.out.println("Could not parse " + nfe); } B[i].setOrder(s.getSelectedItem().toString(),s1.getSelectedItem().toString(),num); TextView objText = (TextView) findViewById(R.id.pl); TextView objText1 = (TextView) findViewById(R.id.pl2); TextView objText2 = (TextView) findViewById(R.id.pl3); objText.setText(B[i].getPizzaName()); objText1.setText(B[i].getPizzaSize()); objText2.setText(B[i].getQuantity()); //**RESOURCE NOT FOUND EXCEPTION** i++; Toast.makeText(SpinPizza.this,edittext.getText(),Toast.LENGTH_SHORT).show(); return true; } return false; } }); Button next1 = (Button) findViewById(R.id.bill); next1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(),Bill.class); // store B= new store(); myIntent.putExtra("myclass",B); myIntent.putExtra("len",i); int j; for (j = 0; j < i; j++) //{myIntent.putExtra("my",s.getSelectedItem().toString()); // myIntent.putExtra("my1",s1.getSelectedItem().toString()); // } { myIntent.putExtra("my",B[j].getPizzaName()); myIntent.putExtra("my1",B[j].getPizzaSize()); myIntent.putExtra("my2",B[j].getQuantity()); } startActivityForResult(myIntent,0); } }); } }
Solution
Quantity is an int:
public int getQuantity()
So you should use this:
objText2.setText(String.valueOf(B[i].getQuantity()));
Otherwise, the operating system will try to find a nonexistent resource for the int
EditText The settext () method is overloaded, so it has the version of string (settext (charsequence text)) and the version of string resource ID (settext (int resid))
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码