【问题标题】:Android Studio, Getting the Error 'cannot resolve method'Android Studio,出现错误“无法解析方法”
【发布时间】:2020-11-23 18:13:51
【问题描述】:

在我的代码块中,我遇到了错误“无法解析方法 'putExtra(java.lang.String, android.widget.TextView)'”。我尝试了一些事情但是我无法解决这个问题。有人知道我可以做些什么来解决这个问题,或者我可以使用的替代代码吗?

Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setPackage("com.whatsapp");
            shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
            shareIntent.putExtra(Intent.EXTRA_TEXT, (TextView)findViewById(R.id.txt_message));
            shareIntent.setType("text/plain");

【问题讨论】:

    标签: java android android-studio error-handling


    【解决方案1】:

    如果您尝试将 TextView (txt_message) 中的文本放入捆绑包中 - 只需像这样(不是 TextView)从中放入文本:

    TextView txt_message = (TextView) findViewById(R.id.txt_message);
    String text = txt_message.getText().toString();
    
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setPackage("com.whatsapp");
    shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
    shareIntent.putExtra(Intent.EXTRA_TEXT, text);
    shareIntent.setType("text/plain");
    

    【讨论】:

      【解决方案2】:

      在意图后添加此代码:

      Bundle extras = shareIntent.getExtras();
      String exampleString = extras.getString(ProjectManager.ID);
      

      【讨论】:

        猜你喜欢
        • 2018-11-13
        • 1970-01-01
        • 2014-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多