为什么我的应用程序在启动时不断崩溃 - Android

时间:2014-04-09 22:18:57

标签: java android crash

关注如何制作按钮和活动的YouTube指南。我将他的代码跟踪到字体大小,当我启动它时它会继续崩溃。谁知道为什么?

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addButtonClickListner();
    }

    public void addButtonClickListner() {
        Button btnNavigator = (Button) findViewById(R.id.button1);
        btnNavigator.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("www.premierleague.com"));
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

1 个答案:

答案 0 :(得分:0)

尝试在网站名称前添加http://!

  

Intent intent = new Intent(Intent.ACTION_VIEW   Uri.parse(" http://www.premierleague.com&#34));

并验证您是否确实已正确命名按钮button1

我的意思是在你的xml中你使用过类似的东西:

<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/button1"