Reputation: 95
The issue stems from the OK Button clickable. the moment I click on the button (in both cases of text and numbers being present/absent in the EditTexts) the app stops working. I can't seem to find where this error is coming from. I've double-checked variables being initialized and the problem doesn't seem to stem from there. Can anyone help out?
The code is below:
public void mInput(View view){
final Dialog dialogManualInput = new Dialog(this);
dialogManualInput.setContentView(R.layout.dialog_A);
dialogManualInput.setTitle("Title");
et1 = (EditText) dialogManualInput.findViewById(R.id.item);
et2 = (EditText) dialogManualInput.findViewById(R.id.price);
et3 = (EditText) dialogManualInput.findViewById(R.id.quantity);
m_adapter = new ArrayAdapter<String>(this,R.layout.activity_A,m_listItems);
checkoutList = (ListView)findViewById(R.id.listview);
checkoutList.setAdapter(m_adapter);
dialogManualInput.show();
Button okButton = (Button) dialogManualInput.findViewById(R.id.ok);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String input_1 = et1.getText().toString();
String input_2 = et2.getText().toString();
String input_3 = et3.getText().toString();
int int_1 = Integer.valueOf(et3);
int int_2 = Integer.valueOf(et2);
String input = "("+et2+") " + et1 +" "+ (int_1*int_2);
if((null!=input_1)&&(null!=input_2)&&(null!=input_3)){
m_listItems.add(input);
m_adapter.notifyDataSetChanged();
}
dialogManualInput.dismiss();
}
});
}
Here is the logcat:
09-23 23:56:01.793 7464-7464/com.kwesimbia.management E/ArrayAdapter? You must supply a resource ID for a TextView
09-23 23:56:01.803 7464-7464/com.kwesimbia.management D/AndroidRuntime? Shutting down VM
09-23 23:56:01.803 7464-7464/com.kwesimbia.management W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x40a99228)
09-23 23:56:01.843 7464-7464/com.kwesimbia.management E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
at android.widget.AbsListView.obtainView(AbsListView.java:2046)
at android.widget.ListView.makeAndAddView(ListView.java:1820)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillFromTop(ListView.java:732)
at android.widget.ListView.layoutChildren(ListView.java:1659)
at android.widget.AbsListView.onLayout(AbsListView.java:1876)
at android.view.View.layout(View.java:11425)
at android.view.ViewGroup.layout(ViewGroup.java:4232)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
at android.view.View.layout(View.java:11425)
at android.view.ViewGroup.layout(ViewGroup.java:4232)
at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
at android.view.View.layout(View.java:11425)
at android.view.ViewGroup.layout(ViewGroup.java:4232)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
at android.view.View.layout(View.java:11425)
at android.view.ViewGroup.layout(ViewGroup.java:4232)
at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
at android.view.View.layout(View.java:11425)
at android.view.ViewGroup.layout(ViewGroup.java:4232)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2498)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
... 33 more
09-23 23:56:01.873 239-1201/? E/EmbeddedLogger? App crashed! Process: com.kwesimbia.management
09-23 23:56:01.873 239-1201/? E/EmbeddedLogger? App crashed! Package: com.kwesimbia.management v1 (1.0)
09-23 23:56:01.873 239-1201/? E/EmbeddedLogger? Application Label: abaawa
09-23 23:56:01.873 239-1201/? W/ActivityManager? Force finishing activity com.kwesimbia.management/.ArtActivity
Upvotes: 0
Views: 166
Reputation: 11314
EDIT 1:
As it seems from Logcat problem is
m_adapter = new ArrayAdapter<String>(this,R.layout.activity_A,m_listItems);
checkoutList = (ListView)findViewById(R.id.listview);
checkoutList.setAdapter(m_adapter);
You are providing m_listItems(I don't know what this is ) and its is looking for an id of a TextView pass a textView's ID in
ArrayAdapter<String>(this,R.layout.activity_A,m_listItems);
Some thing like
ArrayAdapter<String>(this,R.layout.activity_A,R.id.textView01);
Probable Errors
what is this doing you directly putting your edittext to be concatenated with string what it is expected to here may be it should be int_1, or et1.getText() i.e. input_1
String input = "("+et2+") " + et1 +" "+ (int_1*int_2);
If any not initialized as usual NPE for et1, et2, et3 OR
Parsing Exception in these (if you not fill the editText then it must throw exception)
int int_1 = Integer.valueOf(et3);
int int_2 = Integer.valueOf(et2);
Upvotes: 0
Reputation: 3121
The problem could be with your layout. Show us this XML file "R.layout.activity_A" or take a look at it.
Upvotes: 1