1
드래그 앤 터치 리스너를 통해 간단한 앱을 만들려고합니다. 그러나 터치 리스너를 내부 클래스를 통해 TextView 컨트롤로 설정할 때 NullPointerException
: 여기 코드가 있습니다.안드로이드에서 터치 리스너를 구현하는 동안 NULL 포인터 예외가 발생했습니다.
public class MainActivity extends Activity
{
private TextView option1, choice1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
option1 = (TextView)findViewById(R.id.option_1);
setContentView(R.layout.activity_main);
option1.setOnTouchListener(new ChoiceTouchListener()); [NULLPOINTER]
}
private final class ChoiceTouchListener implements OnTouchListener
{
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
if(arg1.getAction() == MotionEvent.ACTION_DOWN)
{
ClipData clipdata = ClipData.newPlainText("","");
DragShadowBuilder shadowbuilder = new DragShadowBuilder(arg0);
arg0.startDrag(clipdata, shadowbuilder, arg0, 0);
return true;
}
else
{
return false;
}
}
}
}