LayoutInflator ()를 사용할 때 Null 포인터 예외가 발생합니까?

user3636645

나는를 사용하여 LayoutInflator사용자의 텍스트를 TableLayout(A의 자식)에 표시하려고 시도하고 scrollView있지만 지금까지는 Null 포인터 예외가 계속 발생합니다. 모든 ID가 잘 작동하고 있습니다. 프로젝트를 정리하여 도움이되는지 확인했지만 아무 소용이 없었습니다. 누구든지 나를 도울 수 있습니까?

그건 그렇고, 오류가 두 곳에서 발생 reminderListTextView.setText(text);하고inflate("test");

암호:

public class MainActivity extends ActionBarActivity {

    private TableLayout reminderTableScrollView;

    // TextView and Button added
    EditText reminderEditText;

    Button addReminderButton;



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

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

        reminderEditText = (EditText) findViewById(R.id.reminderEditText);

        addReminderButton = (Button) findViewById(R.id.enterButton);
        addReminderButton.setOnClickListener(reminderClickListener);
    }

    private OnClickListener reminderClickListener = new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (reminderEditText.getText().toString() == null || reminderEditText.getText().toString() == "") {
                Toast.makeText(getApplicationContext(), "Enter reminder", Toast.LENGTH_SHORT).show();
            } else {
                inflate("Test");
                reminderEditText.setText("");
            }
        }
    };

    public void inflate(String text) {
        LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View reminder = inflator.inflate(R.layout.reminder_layout, null);

        TextView reminderListTextView = (TextView) findViewById(R.id.reminderListTextView);
        reminderListTextView.setText(text);

        reminderTableScrollView.addView(reminder);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.menuAdd) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
그레 그리 긴스 36

실제로 예외가 발생하는 곳은 한 곳뿐입니다. reminderListTextView.setText(text);, 두 줄 은 호출 reminderListTextView.setText(text);될 때 오류가 발생했음을 알려주는 추적 inflate("test");입니다.

시도해보십시오 reminder.findViewById(...);. 레이아웃을 확장 한 뷰를 사용하여 요소를 검색 할 수 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

의도에서 putExtra를 시도 할 때 null 포인터 예외가 발생합니다.

분류에서Dev

CustomList 어댑터를 사용할 때 Null 포인터 예외

분류에서Dev

imageView를 사용할 때 Null 포인터 예외

분류에서Dev

pojo를 사용할 때 예외가 발생합니까?

분류에서Dev

com.sun.jdi.InvocationException이 메서드를 호출하는 동안 "null 포인터 예외"가 발생했습니다. 셀레늄에서 PageFactory를 사용할 때

분류에서Dev

RecyclerView를 설정할 때 null 예외가 발생합니다.

분류에서Dev

빈 Excel 셀의 길이를 확인할 때 Java Null 포인터 예외 발생

분류에서Dev

없어야 할 때 Null 포인터 예외가 있습니까?

분류에서Dev

클래스의 정렬 배열을 병합하려고 할 때 null 포인터 예외가 발생합니다.

분류에서Dev

전역 변수에서 값을 가져 오려고 할 때 Null 포인터 예외가 발생합니다.

분류에서Dev

텍스트 기반 '데이터베이스'를 만들 때 배열을 사용하여 동일한 개체의 여러 인스턴스를 저장하려고 할 때 null 포인터 예외가 발생합니다.

분류에서Dev

TestNG를 통해 Selenium을 실행할 때 Null 포인터 예외 발생

분류에서Dev

Dropbox에서 파일을 다운로드하려고 할 때 null 포인터 예외가 발생합니다.

분류에서Dev

두 번째로 앱을 실행할 때 Null 포인터 예외가 발생합니다.

분류에서Dev

@Value 주석을 사용할 때 왜 Null 예외가 발생합니까?

분류에서Dev

printf 문을 추가 할 때 NULL 포인터 예외가 사라집니다.

분류에서Dev

Google 지역 정보를 사용할 때 Android Null 포인터 예외

분류에서Dev

다른 클래스에서 PrintWriter를 사용할 때 PrintWriter 널 포인터 예외가 발생하는 이유

분류에서Dev

mockito를 사용하는 동안 null 포인터 예외 발생

분류에서Dev

Mockito-Kotlin 테스트에서 Pageable 인수를 캡처하려고 할 때 Null 포인터 예외 발생

분류에서Dev

OnPrepareOptionsMenu를 호출하면 null 포인터 예외가 발생합니다.

분류에서Dev

마스터 페이지에서이 스크립트를 사용할 때이 예외가 발생합니다.

분류에서Dev

getReadableDatabase ()를 호출 할 때 Null 포인터 예외

분류에서Dev

의도를 시작할 때 Null 포인터 예외

분류에서Dev

작업을 시도 할 때 @autowired intance null을 가져와 null 포인터 예외 발생

분류에서Dev

layoutInflator xamarin을 사용하여 팽창하는 동안 런타임 예외가 발생합니까?

분류에서Dev

gridview 콘텐츠를 확장 할 수 없습니다. null 포인터 예외 오류가 발생했습니다.

분류에서Dev

객체 인스턴스에서 for 루프를 올바르게 사용하는 방법-계속 null 포인터 예외가 발생합니다 (Java)

분류에서Dev

System.out.println ()으로 세트를 인쇄 할 때 왜 동시 수정 예외가 발생합니까?

Related 관련 기사

  1. 1

    의도에서 putExtra를 시도 할 때 null 포인터 예외가 발생합니다.

  2. 2

    CustomList 어댑터를 사용할 때 Null 포인터 예외

  3. 3

    imageView를 사용할 때 Null 포인터 예외

  4. 4

    pojo를 사용할 때 예외가 발생합니까?

  5. 5

    com.sun.jdi.InvocationException이 메서드를 호출하는 동안 "null 포인터 예외"가 발생했습니다. 셀레늄에서 PageFactory를 사용할 때

  6. 6

    RecyclerView를 설정할 때 null 예외가 발생합니다.

  7. 7

    빈 Excel 셀의 길이를 확인할 때 Java Null 포인터 예외 발생

  8. 8

    없어야 할 때 Null 포인터 예외가 있습니까?

  9. 9

    클래스의 정렬 배열을 병합하려고 할 때 null 포인터 예외가 발생합니다.

  10. 10

    전역 변수에서 값을 가져 오려고 할 때 Null 포인터 예외가 발생합니다.

  11. 11

    텍스트 기반 '데이터베이스'를 만들 때 배열을 사용하여 동일한 개체의 여러 인스턴스를 저장하려고 할 때 null 포인터 예외가 발생합니다.

  12. 12

    TestNG를 통해 Selenium을 실행할 때 Null 포인터 예외 발생

  13. 13

    Dropbox에서 파일을 다운로드하려고 할 때 null 포인터 예외가 발생합니다.

  14. 14

    두 번째로 앱을 실행할 때 Null 포인터 예외가 발생합니다.

  15. 15

    @Value 주석을 사용할 때 왜 Null 예외가 발생합니까?

  16. 16

    printf 문을 추가 할 때 NULL 포인터 예외가 사라집니다.

  17. 17

    Google 지역 정보를 사용할 때 Android Null 포인터 예외

  18. 18

    다른 클래스에서 PrintWriter를 사용할 때 PrintWriter 널 포인터 예외가 발생하는 이유

  19. 19

    mockito를 사용하는 동안 null 포인터 예외 발생

  20. 20

    Mockito-Kotlin 테스트에서 Pageable 인수를 캡처하려고 할 때 Null 포인터 예외 발생

  21. 21

    OnPrepareOptionsMenu를 호출하면 null 포인터 예외가 발생합니다.

  22. 22

    마스터 페이지에서이 스크립트를 사용할 때이 예외가 발생합니다.

  23. 23

    getReadableDatabase ()를 호출 할 때 Null 포인터 예외

  24. 24

    의도를 시작할 때 Null 포인터 예외

  25. 25

    작업을 시도 할 때 @autowired intance null을 가져와 null 포인터 예외 발생

  26. 26

    layoutInflator xamarin을 사용하여 팽창하는 동안 런타임 예외가 발생합니까?

  27. 27

    gridview 콘텐츠를 확장 할 수 없습니다. null 포인터 예외 오류가 발생했습니다.

  28. 28

    객체 인스턴스에서 for 루프를 올바르게 사용하는 방법-계속 null 포인터 예외가 발생합니다 (Java)

  29. 29

    System.out.println ()으로 세트를 인쇄 할 때 왜 동시 수정 예외가 발생합니까?

뜨겁다태그

보관