- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中,我使用 GsmCellLocation 类来查找特定实例的小区 ID 和 lac。
我简单地定义了类并通过 TextView 将相应的属性显示到 Activity 。
我使用的代码部分是:
TextView textCID;
TextView textLAC;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textCID= (TextView)findViewById(R.id.tv1);
textLAC=(TextView)findViewById(R.id.tv2);
TelephonyManager telph= (TelephonyManager)getSystemService(Testing2Activity.TELEPHONY_SERVICE);
GsmCellLocation cellLocation= (GsmCellLocation)telph.getCellLocation();
if (cellLocation != null) {
int cid1=cellLocation.getCid();
int lac1=cellLocation.getLac();
Log.v("%%%%GGGGF", "Hello");
String s=String.valueOf(cid1);
String s1=String.valueOf(lac1);
textCID.setText(s);
textLAC.setText(s1);
}
代码部分以 NullPointer 异常结束...
请大家帮忙...
错误日志列为:
01-27 12:33:57.802: E/AndroidRuntime(393): FATAL EXCEPTION: main 01-27 12:33:57.802: E/AndroidRuntime(393): java.lang.RuntimeException: Unable to start activity ComponentInfo{sbc.testing.prjct/sbc.testing.prjct.Testing2Activity}: java.lang.NullPointerException 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.os.Handler.dispatchMessage(Handler.java:99) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.os.Looper.loop(Looper.java:123) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-27 12:33:57.802: E/AndroidRuntime(393): at java.lang.reflect.Method.invokeNative(Native Method) 01-27 12:33:57.802: E/AndroidRuntime(393): at java.lang.reflect.Method.invoke(Method.java:521) 01-27 12:33:57.802: E/AndroidRuntime(393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-27 12:33:57.802: E/AndroidRuntime(393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-27 12:33:57.802: E/AndroidRuntime(393): at dalvik.system.NativeStart.main(Native Method) 01-27 12:33:57.802: E/AndroidRuntime(393): Caused by: java.lang.NullPointerException 01-27 12:33:57.802: E/AndroidRuntime(393): at sbc.testing.prjct.Testing2Activity.onCreate(Testing2Activity.java:27) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-27 12:33:57.802: E/AndroidRuntime(393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
最佳答案
我遇到了同样的问题。这背后的原因是模拟器没有任何真正的 GSM 或 CDMA 网络,因此 GsmCellLocation 的对象可能被初始化为 null。然而,当我在具有 GSM 网络的实时设备上尝试相同的操作时,它运行正常。
关于android - android 中的 GSMCellLocation 以异常结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9030055/
我正在尝试通过传递来捕获单元 ID。我成功获得了最初连接到我手机的手机ID。但是,我无法准确解释这一点,似乎不同步。我漫游了好几次,但它总是返回第一个小区 ID。 public class MainA
在我的应用程序中,我使用 GsmCellLocation 类来查找特定实例的小区 ID 和 lac。 我简单地定义了类并通过 TextView 将相应的属性显示到 Activity 。 我使用的代码部
我成功获取了 GsmCellLocation 和相关的 cid 和 lac 信息,但服务小区的 PSC(主扰码)总是返回初始值 -1。谁能得到服务小区的真实PSC值? telephonyManager
我遇到了这个错误: E/AndroidRuntime: FATAL EXCEPTION: main
我是一名优秀的程序员,十分优秀!