Android 在onpostexecute()中打开浏览器

Android 在onpostexecute()中打开浏览器,android,url,browser,android-asynctask,Android,Url,Browser,Android Asynctask,我想在onpostexecute中从异步任务打开浏览器。但我在开始活动时收到nullpointerexception: 我的代码: @Override protected void onPostExecute(String file_url) { AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle("Details");

我想在onpostexecute中从异步任务打开浏览器。但我在开始活动时收到nullpointerexception:

我的代码:

@Override
    protected void onPostExecute(String file_url) {
            AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    alertDialog.setTitle("Details");

        ScrollView scrollview = new ScrollView(context);
        LinearLayout lila1= new LinearLayout(context);
        lila1.setOrientation(1); //1 is for vertical orientation;

        lila1.setBackgroundColor(android.graphics.Color.BLACK);
        scrollview.setBackgroundColor(android.graphics.Color.BLACK);

            final Button adv1 = new Button(context);
            adv1.setOnClickListener(new View.OnClickListener() {

@Override
                public void onClick(View v) {
                     Uri uriUrl = Uri.parse("http://androidbook.blogspot.com/");
                 Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser); //<- does not work

                }
            });
            lila1.addView(adv1);
@覆盖
受保护的void onPostExecute(字符串文件\u url){
AlertDialog AlertDialog=新建AlertDialog.Builder(context.create();
alertDialog.setTitle(“详细信息”);
ScrollView ScrollView=新的ScrollView(上下文);
LinearLayout lila1=新的LinearLayout(上下文);
lila1.setOrientation(1);//1表示垂直方向;
setBackgroundColor(android.graphics.Color.BLACK);
scrollview.setBackgroundColor(android.graphics.Color.BLACK);
最终按钮adv1=新按钮(上下文);
adv1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Uri=Uri.parse(“http://androidbook.blogspot.com/");
意向启动浏览器=新意向(Intent.ACTION_视图,uriUrl);

startActivity(launchBrowser);//您从哪里获得NPE?startActivity(launchBrowser);因此launchBrowser为空,这意味着您以某种方式创建了一些干扰Intent.ACTION_视图的变量(不太可能)或者您的uri解析返回null,使uriUrl为null。在尝试启动活动之前,请插入一些断点或日志或其他内容,看看这些值是什么。两者都很好…可能是因为上下文或视图错误(我在asynctask中启动它)…但我没有得到解决方案asynctask在什么类型的类中?(如服务、活动等)