The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV
在当前短信内容的activity中写
Bundle bun = new Bundle();
bun.putString("message", "短信内容");
Intent in = new Intent(第二个Activity.this, 第一个Activity.class);
in.putExtras(bun);
在要传内容的activity中写:
Bundle bu = this.getIntent().getExtras();
String message = bu.getString("message");//获取短信内容
public class SMSReceiver extends BroadcastReceiver
{
/*当收到短信时,就会触发此方法*/
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++)
{
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
//调用显示短信内容的Activity
Intent intent = new Intent();
intent.setClass(this, MyView.class);
intent.putExtra("sms_body", smsMessage[0].getMessageBody());
startActivity(intent);
}
}
回复三楼,按您所说的改了,
//调用显示短信内容的Activity
Intent intent2 = new Intent();
intent2.setClass(this, Activity01.class);
//setClass出错:The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (SMSReceiver, Class<Activity01>)
intent2.putExtra("sms_body", smsMessage[0].getMessageBody());
startActivity(intent2);
//startActivity出错:The method startActivity(Intent) is undefined for the type SMSReceiver
回复二楼: 二楼思路明确;
回复楼主: 有没有注意到二楼跟三楼的代码区别——intent.setClass(第二个Activity.this, 第一个Activity.class)和intent.setClass(this, 第一个Activity.class),当在方法中调用setClass()这个方法的时候,是可以用this的。挡在内部类中(比如事件监听类OnClickListener)调用这个方法的时候要变为Activity.class。希望能够帮助楼主。
The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV的更多相关文章
- 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...
- The method load(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments (Class, int)
引入别人的项目发现利用HibernateTemplate的load的方法报错了.错误提示为: The method load(Class, Serializable) in the type Hibe ...
- The method format(String, Object[]) in the type String is not applicable for the arguments
今天,我弟遇到一个有意思的错误~ 程序: package com.mq.ceshi1; public class StringFormat { public static void main(Stri ...
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable
开始学习 android 了,学习的是高明鑫老师的android视频教程(android视频教学). 学到第八讲时, 在写动态设置时报错: The method setOnClickListener( ...
- 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 ...
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)
The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...
- The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)
1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...
- [log4j]Error:The method getLogger(String) in the type Logger is not applicable for the arguments
原因:本该导入import org.apache.log4j.Logger; 结果成了import java.util.logging.Logger; 如果硬把private static Logge ...
- .replace(R.id.container, new User()).commit();/The method replace(int, Fragment) in the type FragmentTransaction is not app
提示错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arg ...
随机推荐
- 64_p3
perl-Locale-Msgfmt-0.15-17.fc26.noarch.rpm 12-Feb-2017 03:11 20558 perl-Locale-PO-0.27-6.fc26.noarch ...
- 以应用带动SDN发展(CDN峰会 工信部杨崑)(转)
以应用带动SDN发展(CDN峰会 工信部杨崑) SDNAP推荐:这是在亚太全媒体SDN峰会由工信部研究院秘书长杨崑做的关于SDN的一个演讲,本人认为主讲者通过对整 个信息服务体系的精简归纳总结,剥 ...
- 关于HTML5服务器发送事件(SSE)
最近在看 W3School 上关于 HTML 5 的教程.在看到 HTML 5 服务器发送事件 ( SSE, server-sent event ) 时,没怎么弄明白示例代码是怎么回事,寻找其他教程, ...
- AssetBundle——外部加载资源Asset
几篇很不错的文章 AssetBundle创建到使用入门 全面理解Unity加载和内存管理 实用的创建AssetBundle的脚本 相关资源 相关的共享资源下载 本共享包括创建assetbund ...
- Python抓取微博评论
本人是张杰的小迷妹,所以用杰哥的微博为例,之前一直看的是网页版,然后在知乎上看了一个抓取沈梦辰的微博评论的帖子,然后得到了这样的网址 然后就用m.weibo.cn进行网站的爬取,里面的微博和每一条微博 ...
- HTTP协议头注射漏洞实例
HTTP 响应头文件中包含未经验证的数据会引发 cache-poisoning.cross-site scripting.cross-user defacement.page hijacking.co ...
- 设置或者获取CheckboxList控件的选中值
1.设置CheckBoxList选中的值 /// <summary> /// 设置CheckBoxList中哪些是选中了的 /// </summary> /// <par ...
- 关于Web2.0概念的一篇小短文
Web2.0程序设计的第一篇作业,写了就顺手放上来吧. 在互联网泡沫破裂数年后,Tim O'Reilly与John Battelle总结了互联网产业复兴过程中出现的一系列现象,在2004年举办的第一届 ...
- 语音性别识别 - 使用R提取特征
步骤 1)安装R.windows操作系统安装包的链接:https://cran.r-project.org/bin/windows/base/ 2)切换当前路径为脚本所在路径 点击 文件 > 改 ...
- 【PAT】1001. A+B Format (20)
1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, the digits m ...