-1

IN Edittext seterror working perfecty but Textview how to seterror

I tried coding so for

Textview  spinner = (TextView) view.findViewById(R.id.spinner_txt);
spinner_txt.setText(name);///from the coding i am setting settext
String spinnertxt=spinner.getText.toString;

if(spinnertxt.length()==0){
    spinner_txt.setError("select the representative");
    }
spinner_txt.requestFocus();
jaya oriya
  • 83
  • 3
  • 17
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Atef Hares Mar 30 '17 at 04:52
  • oh dear! please check if you have initialized this spinner_txt – Rushi Ayyappa Mar 30 '17 at 05:07

2 Answers2

1
Textview  spinner = (TextView) view.findViewById(R.id.spinner_txt);

spinner_txt.setText(name);///from the coding i am setting settext

Over here you are setting settext to spinner_txt instead of spinner. I wonder how is your setText is getting called.

String spinnertxt=spinner.getText.toString;

You are getting NullPointerException because your spinner textview does not contain any text and so, snippertxt is null and you are trying to get length of a null object.

Try this:-

spinner.setText(name);
String spinnertxt=spinner.getText.toString;
Malwinder Singh
  • 6,644
  • 14
  • 65
  • 103
0

Actually my question to seterror for textview....Like edit text .... And my answer was I found that edittext function work as textview by change the attrubutes in xml. so keypad is not enable and focusableInTouchMode also false in android studio

android:focusable="false"
            android:clickable="true"
            android:focusableInTouchMode="false"
jaya oriya
  • 83
  • 3
  • 17