last day (15 days later) » 

11:19 AM
0
A: Add numbers from EditTexts

Akhil JainHere is how you would do it addNumberFromText() { int total=0; for(int i=0;i<listView.getChildCount();i++) { View wantedView = listView.getChildAt(i); EditText edtText=view.findViewById(R.id.specificEditTextId); //not checking wheter integer valid or not, Plea...

 
It doesn't work... It gives me a error: Cannot make a static reference to the non-static method getChildCount() from the type ViewGroup
 
where did you actually write the above code, adapter or anonymous inner class???
 
Inside the main activity
 
can you please post the logcat error
 
I can't run the app. The errors are red exclamation marks
 
11:19 AM
in which file MainActivity or adapter?? cause non static reference could possibly be due to ViewHolder and reference Ui components
 
Inside PersActivity, which is the main activity of the app
 
1.) please take screenshot and share it which line show error, did you make addNumberFromText() method static??
 
i.imgur.com/Lv4Q39O.png?1 I did not make addNumberFromText static
 
1. you are new to android programming, that is very obvious. just tell one thing, the id of the view which you trying to add, textview or edittext or whatever
 
Yes, I'm new to android programming. The id of the TextView is subjectmark
 
11:19 AM
see now, i would highly recommend to use chat discussion for further queries
 
Yes, thank you so much
 
did the solution woked??
worked??
 
No, it gives me the same error..
 
ok share the screenshot again, what is this seriously??
infact share the entire updated mainactivity code
 
OK
public class PersActivity extends Activity {

Button start, calcaverage1;

private SubjectAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subject_list_view);

setupListViewAdapter();

setupAddMarkButton();

// Accept button
Button acceptbn= (Button)findViewById(R.id.start1);
acceptbn.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
Intent intent = new Intent(PersActivity.this, MainActivity.class);
Sorry, wait a moment, please
I better send it to you by pastebin
Here it is
Thanks in advance for your help, I appreciate it very much
 
11:47 AM
Here are the errors: i.imgur.com/VeakBuI.png
 
12:42 PM
i saw the image, please add void to method name
void addNumberFromText()
and then share update code again on paste bin or here
what you shared on pastebin,
what you provided code here on discussion and
the image are all different
 
ok, quick update
do this
 
Updated full code: pastebin.com/j5HMpXW4
 
public class PersActivity extends Activity
{

Button start, calcaverage1;

private SubjectAdapter adapter;
ListView atomPaysListView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.subject_list_view);
atomPaysListView = (ListView)findViewById(R.id.subject_list_item);
setupListViewAdapter();

setupAddMarkButton();

// Accept button
Button acceptbn= (Button)findViewById(R.id.start1);
acceptbn.setOnClickListener(new OnClickListener()
use this exact code
did it work???
 
Sorry for changing the code: I just changed atomPaysListView to MarkListView, but that doesn't affect the code
 
12:56 PM
send again the updated code, i want to know what exactly is wrong??
 
subjectmark is an EditText
 
please dont decalre MarkListview inside setupListViewAdapter
that exactly is your problem
 
OK, I'll check it
 
the control need to accessible throughout class, please learn basic of programming

public class PersActivity extends Activity {

Button start, calcaverage1;

private SubjectAdapter adapter;
ListView MarkListView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subject_list_view);
MarkListView = (ListView)findViewById(R.id.subject_list_item);
setupListViewAdapter();

setupAddMarkButton();

// Accept button
Button acceptbn= (Button)findViewById(R.id.start1);
check
 
OK, partially corrected
I send you image
I didn't notice the listview wasn't declared, sorry
If I write: TextView txv=(TextView)findViewById(R.id.subjectmark);
Then the error disappears
 
1:06 PM
change that line to
TextView txv=(TextView)wantedView.findViewById(R.id.subjectmark);
 
OK there are no more errors, thank you
But when I press the button, the numbers are not added
 
which button, please tell that too
 
I've defined a button: calcaverage1
What I wanted is to sum the numbers when pressing that button
 
listen crefully, in oncreate method, after initalising button

calcaverage1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v)
{
addNumberFromText();
}
});
 
OK, I've done it but when executing the app stops
LogCat:
08-21 15:13:36.689: E/AndroidRuntime(2883): FATAL EXCEPTION: main
08-21 15:13:36.689: E/AndroidRuntime(2883): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.isa.gestordecurso/com.isa.gestordecurso.PersActivity}: java.lang.NullPointerException
08-21 15:13:36.689: E/AndroidRuntime(2883): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-21 15:13:36.689: E/AndroidRuntime(2883): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
I've defined a TextView where I'd like to show the result, but I don't see any call to that TextView
 
1:19 PM
i told you to initalize
you also need to initalie text view
intialization of a view is
like this for eg
TextView txv=(TextView)wantedView.findViewById(R.id.subjectmark);
//do not copy paste the above line
 
But that TextView is already initialized
 
that is why i said it is exampple,
intialize textview where you have to display result
 
1:38 PM
Atleast accept the answer man
 
 
1 hour later…
2:38 PM
Sorry, I had to go
Thank you so much for your help ;)
 
 
5 hours later…
8:00 PM
:)
 

last day (15 days later) »