zoukankan      html  css  js  c++  java
  • The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

    package comxunfang.button;
    
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
    
    
    public class MainActivity extends ActionBarActivity {
        private Button bt;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            bt = (Button) findViewById(R.id.btn);
            
            //第一种
            bt.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    Toast.makeText(this, "这是第1种写法",0).show();
                }
            });
        }

    如果这样写的话,就会报Multiple markers at this line
        - Line breakpoint:MainActivity [line: 22] - onClick(View)
        - The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){},
         String, int)

    这样的错,如果把Toast.makeText(this, "这是第1种写法",0).show();改成Toast.makeText(MainActivity.this, "我弹出来了", 0).show() ;则是正常的

    这说明上下文的对象导致这样的结果

  • 相关阅读:
    nginx用户统计
    mysql用户和授权
    memcache操作
    nginx memcache缓存
    memcached安装启动
    Unity 菜单拓展
    用C#创建XML, XML格式化输出
    解析swf文件头,获取flash的原始尺寸
    kinematic与static刚体不会触发任何接触回调
    git使用
  • 原文地址:https://www.cnblogs.com/ouysq/p/4552820.html
Copyright © 2011-2022 走看看