Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Android error while creating dynamic row

Posted on 2012-03-29
3
Medium Priority
?
550 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 1200 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 800 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
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.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

963 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