Solved

Android error while creating dynamic row

Posted on 2012-03-29
3
541 Views
Last Modified: 2012-03-29
hello there,

i have an activity which takes some user input and when the user clicks the add  button,the input should get added to table row.but i get error when i try to add.i am able to get the table header,but cannot show input record.i have attached the error log and the code.please help.

cheers
zolf
log.txt
Order.java
0
Comment
Question by:zolf
3 Comments
 
LVL 1

Accepted Solution

by:
garikapatisuresh earned 300 total points
ID: 37781004
Dear zolf,

Based on your attached log and the code I identified the problem.

in createRow(int qty2, String productSelected2) method, you are trying to set qty2 as a resource id to the TextView labelDATE. But the qty2 is not a raw string resource defined in your res folder. Here qty2 hold the value of qty_text_input TextView value.

Hence the labelDATE TextView is trying to find a string with the given integer value. But it was not able to identify any where. Hence crash occured.

Probably what you have to do is, you have to use TextView's one more polymorphic method setText(String).

I mean, in createRow(--) method,

use
labelDATE.setText(qty2+""); or labelDATE.setText(Integer.toString(qty2));
instead of
labelDATE.setText(qty2);

All the best...
0
 
LVL 8

Assisted Solution

by:Santhana
Santhana earned 200 total points
ID: 37781016
Hi Zlof,

In onClick() method  you are getting the string from the EditText and then converting that string into Integer.
In  createRow() method you are trying to access the string rresource by using this integer
This is not a string resource. It is just a String

So change the code like this....

      try{
            Log.d("ZAJ", qty_text_input.getText().toString());
//               qty = Integer.parseInt(qty_text_input.getText().toString());      
                                 }
            catch (NumberFormatException ex)
            {
               // 'price' does not contain a valid integer
                  ex.printStackTrace();
            }
            createRow(qty_text_input.getText().toString() ,productSelected);
              }



private void createRow(String qty2, String productSelected2)
{
.............
      TextView labelDATE = new TextView(this);
       labelDATE.setId(200+count);
       labelDATE.setText(qty2);

...........
}
0
 

Author Closing Comment

by:zolf
ID: 37783198
cheers
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
If your app took Google’s lash recently, here are the 5 most likely reasons.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question