When calling

public void onPress(int primaryCode) { startActivity(new Intent(MainActivity.this,swipe.class)); } 

This error comes out.

 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.lol.keyboard/com.example.lol.keyboard.swipe}: java.lang.InstantiationException: java.lang.Class<com.example.lol.keyboard.swipe> has no zero argument constructor 

swipe.class:

 public class swipe extends View { public swipe(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onTouchEvent(MotionEvent event) { float touchX = event.getX(); float touchY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_MOVE: MainActivity.coord.add(touchX); MainActivity.coord.add(touchY); } return true; } 
  • one
    And the question is what? And the error text clearly states that the swipe class (the name of which for some reason starts with a small letter) does not have a constructor without parameters. Accordingly, either create such a constructor in the swipe class, or do not use this code. And the class is still called Swipe . - Regent
  • one
    You are trying to start the com.example.lol.keyboard.swipe class as an Activity , although in fact it is a heir to View . You have to decide what you need - to start the activity or to insert the widget somewhere - woesss

1 answer 1

Using the startActivity method, startActivity can start only activites, i.e. classes that inherit an Activity or AppCompatActivity . You have a class that inherits View , which does not inherit actviti.

If you still need to activate it, then inherit the class from it and remove all constructors - they are used by the system for activations and fragments and should not be changed by the developer