سؤال

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