P
P
Pavel Dmitriev2013-12-22 16:49:08
Java
Pavel Dmitriev, 2013-12-22 16:49:08

Why doesn't site call work in android?

There is such code in menu/main.xml

<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/item"
        android:icon="@drawable/ic_logo"
        android:showAsAction="always"
        android:title="@string/item1"
        android:onClick="Click"
        >
    </item>
</menu>

and the method in mainactivity.java is like this
public void Click(View view) {
        Uri address = Uri.parse("http://example.ru");
        Intent openling = new Intent(Intent.ACTION_VIEW, address);
        startActivity(openling);
    }

The project compiles, but when launched on a tablet, it immediately crashes with an error precisely because of this method. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tarikb, 2013-12-23
@tarikb

You need at least an error log. most likely departure to
Uri address = Uri.parse(" example.ru ");

A
Alexey, 2013-12-23
@Alexious_sh

Even if there are no browsers in the system, there will be a crash with an ActivityNotFoundException exception. Here it is clearly worth adding handlers to the code ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question