Reputation: 1
When I run the app there is an Fatal exception error
android.content.ActivityNotFoundException: No Activity found to handle Intent
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get butten
Button bt= (Button) findViewById(R.id.bt);
// set a monitor
bt.setOnClickListener(new MyListener());
}
class MyListener implements View.OnClickListener{
public void onClick(View v) {
EditText et = (EditText) findViewById(R.id.et);
String number = et.getText().toString();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel"+number));
startActivity(intent);
}
}
}
Upvotes: 0
Views: 2024
Reputation: 3513
Very simple, your device does not have an app that handles phone calls. It is probably a tablet. When coding, you have to code for such errors, by using try...catch.
Upvotes: 1
Reputation: 3129
You have to specify the Intent
by using a context
& class name.
Since you haven't provide your Manifest file the easiest way to avoid the error is changing the code as follows
Intent intent = new Intent(this,MainActivity.class);
More details from android Documentation
android.content.Intent public Intent(android.content.Context packageContext,
java.lang.Class<?> cls)
Create an intent for a specific component. All other fields (action, data, type, class) are null, though they can be modified later with explicit calls. This provides a convenient way to create an intent that is intended to execute a hard-coded class name, rather than relying on the system to find an appropriate class for you; see setComponent for more information on the repercussions of this.
Parameters:
packageContext
- A Context of the application package implementing this class. cls - The component class that is to be used for the intent.
Upvotes: 0