문제

I just want to create an app where when the user clicks on the launcher icon, it takes them to my website. I found example code to do this in stackoverflow, and it almost works. The code below does successfully launch a website, bit it also displays a pop up right after saying "The application John Project (process com.john.project) has stopped unexpectedly. Please try again.". I'm guessing I'm not shutting down my app properly? Here's my MainActivity.java:

package com.john.project;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        String url = "http://project.john.com/";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);

        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

    }

    @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;
    }

}
도움이 되었습니까?

해결책

You must call super.onCreate() in onCreate(), otherwise you will crash with a SuperNotCalledException.

다른 팁

Add super.onCreate() at the top of onCreate().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top