2
I tried to make the user click on a certain button, it was directed to a site, in this case google, but it did not work.
The app starts normally, but when you click the app button, it stops:
This appears in the log Event:
NullPointerException: Error executing task com.android.tools.idea.uibuilder.editor.NlPreviewForm$$Lambda$186/56197713@4193ab80
Mainactivity.java:
package genesysgeneration.bb;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button btnSite;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSite=(Button)findViewById(R.id.btnsite);
btnSite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("www.google.com"));
startActivity(it);
}
});
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="genesysgeneration.bb.MainActivity">
<Button
android:text="Coisas de maxo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnsite"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
THANK YOU VERY MUCH MANO, FUNFOU! !
– Boneco Sinforoso