开发中碰到的问题:The method getSystemService(String) is undefined for the type CourseFragment
来源:互联网 发布:做淘宝销售什么意思 编辑:程序博客网 时间:2024/06/06 15:36
【问题】
android程序:
1
2
3
4
5
6
7
8
class
UsbDeviceStateReceiver
extends
BroadcastReceiver{
public
void
onReceive(Context context, Intent intent) {
...
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
...
}
}
结果出错:
The method getSystemService(String) is undefined for the type UsbDeviceStateReceiver如图:
【折腾过程】
1.参考:
getSystemService is undefined for the type for GetLocation
去:
把:
1
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
改为:
1
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
即可。
【总结】
getSystemService是Activity中的context才有的。
所以别的部分直接调用会找不到。
所以要从context中去调用getSystemService即可。
0 0
- 开发中碰到的问题:The method getSystemService(String) is undefined for the type CourseFragment
- The method isEmpty() is undefined for the type String/String
- The method setCharacterEncoding(String) is undefined for the type HttpServletResponse
- The method setCharacterEncoding(String) is undefined for the type HttpServletResponse
- The method fromObject(String) is undefined for the type JSONObject
- The method isEmpty() is undefined for the type String
- The method setCharacterEncoding(String) is undefined for the type HttpServle
- he method isEmpty() is undefined for the type String/String
- android开发:The method getSupportFragmentManager() is undefined for the type
- 问题“The method getDispatcherType() is undefined for the type HttpServletRequest”
- 对于The method consume(HttpEntity) is undefined for the type EntityUtils问题的解决办法
- 关于The method getResources() is undefined for the type XX的问题处理
- 部署Tomcat8遇到的 “The method getDispatcherType() is undefined for the type HttpServletRequest” 问题
- the method d(string string) is undefined for the type log
- jfinal报错The method renderText(String) is undefined for the type HelloController
- 运行maven项目报错:The method queryForInt(String) is undefined for the type JdbcTemplate
- jeeplus 使用:The method setShi(String) is undefined for the type addRow_tag
- 错误提示:The method parseInt(String) is undefined for the type Loginsample
- 即时通讯之基本数据写入到输出流中
- 支付宝支付 - 两个程序 app 之间的跳转
- java笔试题(三)
- Openfire开发配置,Openfire源代码配置,OpenFire二次开发配置
- mount 命令中文man
- 开发中碰到的问题:The method getSystemService(String) is undefined for the type CourseFragment
- java与c++程序在编译和运行上有什么区别
- 6个用于大数据分析的最好工具
- c# ora-00177
- IOS 使用高德地图一次定位
- 加密算法总结
- EventBus 3.0的用法详解
- 平衡二叉树AVL详解
- RecycleView简单使用