Android速率按钮语法错误

时间:2011-07-09 05:55:55

标签: java android

我在令牌“marketrate”上收到错误语法错误,在此令牌后期望VariableDeclaratorId ... Uri.parse(“https://market.android.com/details?id=com.synamegames.giveaway”);

令牌上的语法错误,错放的构造... startActivity(market);

        private void makeDialog() {     

        AlertDialog.Builder about = new AlertDialog.Builder(this);      

        about.setMessage("About The Giveaway");

        about.setPositiveButton("Rate", new DialogInterface.OnClickListener() {
            Intent market = new Intent(
                    "android.intent.action.VIEW", 

                startActivity(market);
            public void onClick(DialogInterface arg0, int arg1) {
//action
            }
        });

        about.setNegativeButton("Close", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {}
        });

        about.show();
    }

}

2 个答案:

答案 0 :(得分:1)

我认为你有两个问题。

首先,你在这里有不匹配的括号:

Intent market = new Intent(
    "android.intent.action.VIEW", 
    Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway");
startActivity(market);

我认为在Uri.parse调用之后需要一个提取括号,以关闭Intent构造函数调用:

Intent market = new Intent(
    "android.intent.action.VIEW", 
    Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway"));
startActivity(market);

或者提取Uri.parse来电开头:

Uri uri = Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway");
Intent market = new Intent("android.intent.action.VIEW", uri);
startActivity(market);

其次,您在OnClickListener()内部子类中有效地获得了一段代码,而不是在初始化块或方法中。你的意思是把它放在onClick处理程序中吗?

about.setPositiveButton("Rate", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
        Uri uri = Uri.parse("...");
        Intent market = new Intent("android.intent.action.VIEW", uri);
        startActivity(market);
    }
});

答案 1 :(得分:0)

请试试这个,  我测试了代码并按照要求工作..

AlertDialog.Builder about = new AlertDialog.Builder(this);

    about.setMessage("About The Giveaway");

    about.setPositiveButton("Rate", new DialogInterface.OnClickListener() 
    {
        Intent market = new Intent("android.intent.action.VIEW",Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway"));

        public void onClick(DialogInterface arg0, int arg1) 
        {
                    //action
            startActivity(market);  

        }
    });

    about.setNegativeButton("Close", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface arg0, int arg1) 
        {

        }
    });

    about.show();

尝试在Main / UI Thread中运行代码。