-1

I'm new to android I'm trying to get the student details from sample form to display them in next screen, but it's throwing an error which I mentioned in above title. So, first I'm creating sample form for entering student details through main activity and including it's xml file, after entering the details and pressing submit button in the next screen it should print the above details name --(name which entered in sample form) age -- age " gender -- gender " education --edu " But it's not printing the details.

My displayActivity.java code is:

package first.sample.com.task1;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;

public class DisplayActivity extends Activity {
private TableLayout tableLayout;
    private int student_display_age;
    private int student_display_name;
    private int student_display_gender;
    private int student_display_edu;


    @Override
    protected void onCreate(Bundle savedInstanecState) {

        super.onCreate(savedInstanecState);
        setContentView(R.layout.display_activity);

        Bundle b = getIntent().getExtras();

        tableLayout=(TableLayout)findViewById(R.id.tableLayout);

        TextView name = (TextView) findViewById(R.id.nameValue);
        TextView age = (TextView) findViewById(R.id.ageValue);
        TextView eduText = (TextView) findViewById(R.id.spinner);
        TextView gender = (TextView) findViewById(R.id.genderValue);


            View tableRow= LayoutInflater.from(this).inflate(R.layout.table_item,null,false);
            TextView student_display_name1 = (TextView) tableRow.findViewById(R.id.student_display_name);
            TextView student_display_age1 = (TextView) tableRow.findViewById(R.id.student_display_age);
            TextView student_display_gender1 = (TextView) tableRow.findViewById(R.id.student_display_gender);
            TextView student_display_edu1 = (TextView) tableRow.findViewById(R.id.student_display_edu);

            ((TextView) tableRow.findViewById(R.id.student_display_name)).setText(name.getText());
            ((TextView) tableRow.findViewById(R.id.student_display_age)).setText(age.getText());
            ((TextView) tableRow.findViewById(R.id.student_display_gender)).setText(gender.getText());
            ((TextView) tableRow.findViewById(R.id.student_display_edu)).setText(eduText.getText());



        student_display_edu1.setText(student_display_edu);
        student_display_name1.setText(student_display_name);
        student_display_gender1.setText(student_display_gender);
        student_display_age1.setText(student_display_age);

           tableLayout.addView(tableRow);

    }

}`

and my table_item.xml file is

'

Blockquote

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:orientation="vertical"
    android:collapseColumns="0">

    <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="384dp"
        android:layout_height="106dp">

        <TextView
            android:id="@+id/student_display_gender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="2" />

        <TextView
            android:id="@+id/student_display_age"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_marginTop="0dp" />

        <TextView
            android:id="@+id/student_display_edu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="3" />

        <TextView
            android:id="@+id/student_display_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="4" />


    </TableRow>
</TableLayout>

</RelativeLayout>'

' The error is showing because of the following code 
student_display_edu1.setText(student_display_edu);
student_display_name1.setText(student_display_name);
student_display_gender1.setText(student_display_gender);
student_display_age1.setText(student_display_age); '

please help me. I'm stuck here.

enter code here   }
prithvi Raj
  • 111
  • 1
  • 1
  • 6
  • 4
    Possible duplicate of [android.content.res.Resources$NotFoundException: String resource ID #0x0](https://stackoverflow.com/questions/20177003/android-content-res-resourcesnotfoundexception-string-resource-id-0x0) – Umair Jun 28 '18 at 14:08
  • https://stackoverflow.com/a/48049073/3166697 - this is the answer of your question – Dima Kozhevin Jun 28 '18 at 17:00

1 Answers1

1

student_display_age1.setText(student_display_age);

student_display_age is of type int. Whenever you use setText(int), then Android will look up in your Resources (Strings.xml) to see if it can find that int. Considering it can't be found, the error will be thrown. To solve this issue, use either of the following options:

student_display_age1.setText(""+student_display_age);

or

student_display_age1.setText(String.valueOf(student_display_age));

Zun
  • 1,553
  • 3
  • 15
  • 26
  • @ZUNZAE tableLayout.addView(tableRow); Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TableLayout.addView(android.view.View)' on a null object reference at first.sample.com.task1.DisplayActivity.onCreate(DisplayActivity.java:65) this is the error again it is showing, is there any problem in table_item.xml file ?? Once please check that and let me know. Thanks for your help. – prithvi Raj Jun 29 '18 at 05:16