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 ...
随机推荐
- MySQL sleep过多解决方法
睡眠连接过多,会对mysql服务器造成什么影响? 严重消耗mysql服务器资源(主要是cpu, 内存),并可能导致mysql崩溃. 造成睡眠连接过多的原因? 1. 使用了太多持久连接(个人觉得,在高并 ...
- iOS 取消按钮高亮显示方法
objective-C 第1种方法: 设置按钮的normal 与 highlighted 一样的图片, 不过如果你也需要selected状态下的图片, 就不能这么做, 这样做在取消选中状态的时候就会显 ...
- 服务号使用微信网页授权(H5应用等)
获取授权准备 AppId 服务号已经认证且获取到响应接口权限 设置网页授权域名 公众号设置 - 功能设置 - 网页授权域名.注意事项: 回调页面域名或路径需使用字母.数字及"-"的 ...
- 在flask中返回requests响应
在flask服务端,有时候需要使用requests请求其他url,并将响应返回回去.查阅了flask文档,About Responses,可以直接构造响应结果进行返回. If a tuple is r ...
- CSS背景横向平铺BUG,解决方法
给定DIV一个背景图片横向平铺,缩小浏览器,拉动横向滚动条,此时触发此BUG:背景图片平铺不完整 解决办法: 1.把背景图片写在BODY上,此办法局限于没有使用iframe的情况下,所以少用 2.设定 ...
- [实战]MVC5+EF6+MySql企业网盘实战(5)——登录界面,头像等比例压缩
写在前面 关于该项目,已经很久没更新了.实在是找不到一个好的ui,没办法就在网上找了一个还不错的,就凑合着先用着吧,先出第一版,以后的再想着去优化.最近更新与网盘项目相关的内容是准备在项目中使用一个美 ...
- WPF 获取指定文件的Icon
C# var icon = System.Drawing.Icon.ExtractAssociatedIcon(@"filepath"); var m = new MemorySt ...
- 【LOJ】#2586. 「APIO2018」选圆圈
题解 不旋转坐标系,TLE,旋转坐标系,最慢一个点0.5s--maya,出题人数据水平很高了-- 好吧,如果你不旋转坐标系,写一个正确性和复杂度未知的K - D树,没有优化,你可以得到87分的好成绩 ...
- LoadRunner函数–lr_vuser_status_message
http://wenku.baidu.com/link?url=KbKGldKUkam4VyH5Z2doesA0ovQpuwM9nX_SnVMtWjo6rJPxj9DqB51z_m1giMbVo5Db ...
- c++ 单例模式研究
一篇博文:C++ 单例模式的几种实现研究 中 看到的几段代码 懒汉模式 class Singleton { public: static Singleton* GetInstance() { if ( ...