BamsBamx
BamsBamx

Reputation: 4266

Why does this onTouchListener throw NullPointerException?

I dont undestand, i have used this same code in main activity from the same app, and worked well. But when i use this in other activity, it throws me NullPointer.... Why is this?

     private TextView drag_txtSeconds; 

     @Override
 public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drag_layout); 

       drag_txtSeconds = (TextView)findViewById(R.id.TxtSeconds); 

       drag_txtSeconds.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v,MotionEvent event) {
                return true; 
            }});
         }

Hope you can help me :)

Upvotes: 0

Views: 498

Answers (1)

ScouseChris
ScouseChris

Reputation: 4397

Make sure your file drag_layout has a TextView with the attribute:

android:id="@+id/TxtSeconds"

This is case sensitive, and may be due to the capital letters, try using all lowercase in the layout and in your code.

Upvotes: 1

Related Questions