othSettings活动强制关闭并抛出NullPointerE

othSettings活动强制关闭并抛出NullPointerE

本文介绍了安卓:试图启动BluetoothSettings活动强制关闭并抛出NullPointerException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开的标准窗口的蓝牙设置(使用设备名,可发现性等等)。

I'm trying to bring up the standard window for Bluetooth Settings(with Device name, Discoverability etc).

然而,随着 startActivity一般方法(意向)结尾NullPointerException异常指向 BluetoothSettings.java的onCreate:135

However, general approach with startActivity(intent) ends with NullPointerException pointing toBluetoothSettings.java onCreate:135.

检查了Android code,我发现,在第135行,他们得到的意图的一些附加功能。所以我prepare相同的演员(名字我已经在Android的核心BluetoothDevicePicker界面中找到),并发出了它 - 与NullPointerException异常同样的效果

Checking with the Android code, I've found that at line 135 they get some extras from the intent. So I prepare the same extras (names I've found in android core BluetoothDevicePicker interface) and issue it -- the same effect with NullPointerException.

可能是额外的过错名字我prepare?

Might be the wrongs names of the extras I prepare?

那么,有没有一种方法,我可以看到那些群众演员(地名尤其是)从意图系统本身提交,当我打开蓝牙设置手动像个用户?

So is there a way I can see those extras (with names especially) from the intent the system itself submits when I open Bluetooth Settings manually acting like a user?

非常感谢。

我的code是:

Intent settingsIntent = new Intent();
settingsIntent.setClassName("com.android.settings",      com.android.settings.bluetooth.BluetoothSettings");
settingsIntent.putExtra("android.bluetooth.devicepicker.extra.LAUNCH_PACKAGE", "mypackage.bttoggle");
settingsIntent.putExtra("android.bluetooth.devicepicker.extra.DEVICE_PICKER_LAUNCH_CLASS", "mypackage.bttoggle.BluetoothWidget");
PendingIntent settingsPendingIntent = PendingIntent.getActivity(context, 0, settingsIntent, 0);
views.setOnClickPendingIntent(R.id.btnSettings, settingsPendingIntent);

这是一个小部件,所以我需要使用PendingIntent。

It's a widget so I need to use PendingIntent.

这code得到下面的异常运行时:

This code get the following Exception at runtime:

ERROR / AndroidRuntime(4905):未捕获的处理程序:螺纹主力退出因  未捕获的异常错误/ AndroidRuntime(4905):  java.lang.RuntimeException的:无法启动的活动  ComponentInfo {com.android.settings / com.android.settings.bluetooth.BluetoothSettings}:  显示java.lang.NullPointerException错误/ AndroidRuntime(4905):在  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)  ERROR / AndroidRuntime(4905):在  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)  ERROR / AndroidRuntime(4905):在  android.app.ActivityThread.access $ 2200(ActivityThread.java:126)  ERROR / AndroidRuntime(4905):在  android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1932)  ERROR / AndroidRuntime(4905):在  android.os.Handler.dispatchMessage(Handler.java:99)  ERROR / AndroidRuntime(4905):在android.os.Looper.loop(Looper.java:123)  ERROR / AndroidRuntime(4905):在  android.app.ActivityThread.main(ActivityThread.java:4595)  ERROR / AndroidRuntime(4905):在  java.lang.reflect.Method.invokeNative(本机方法)  ERROR / AndroidRuntime(4905):在  java.lang.reflect.Method.invoke(Method.java:521)  ERROR / AndroidRuntime(4905):在  com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860)  ERROR / AndroidRuntime(4905):在  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)  ERROR / AndroidRuntime(4905):在dalvik.system.NativeStart.main(母语  法)ERROR / AndroidRuntime(4905):产生的原因:  显示java.lang.NullPointerException错误/ AndroidRuntime(4905):在  com.android.settings.bluetooth.BluetoothSettings.onCreate(BluetoothSettings.java:135)  ERROR / AndroidRuntime(4905):在  android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)  ERROR / AndroidRuntime(4905):在  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)  ERROR / AndroidRuntime(4905):11 ...更多

经过调查,我发现,在BluetoothSettings.java线135有:

After investigating, I found that at line 135 in BluetoothSettings.java there is:

public class BluetoothSettings extends PreferenceActivity
{

 ... 132 mNeedAuth = intent.getBooleanExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
 133 mFilterType = intent.getIntExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, 134 BluetoothDevicePicker.FILTER_TYPE_ALL);
 135 mLaunchPackage = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE);
 136 mLaunchClass = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS); ...

我看着BluetoothDevicePicker找群众演员的名字:

I looked into BluetoothDevicePicker to find the names of the extras:

public interface BluetoothDevicePicker { public static final String EXTRA_NEED_AUTH = "android.bluetooth.devicepicker.extra.NEED_AUTH";
public static final String EXTRA_FILTER_TYPE = "android.bluetooth.devicepicker.extra.FILTER_TYPE";
public static final String EXTRA_LAUNCH_PACKAGE = "android.bluetooth.devicepicker.extra.LAUNCH_PACKAGE";
public static final String EXTRA_LAUNCH_CLASS = "android.bluetooth.devicepicker.extra.DEVICE_PICKER_LAUNCH_CLASS";

所以,我用他们在我的code至prepare这些特殊的演员。

So, I use them in my code to prepare those particular extras.

推荐答案

这code对我的作品

    Intent intentBluetooth = new Intent();
    intentBluetooth.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
    startActivity(intentBluetooth);

您需要测试它在手机上,otherways您将获得在模拟器上奇怪的错误(不支持蓝牙)。

You need to test it on the phone, otherways you will get strange errors on the emulator (Bluetooth not supported).

这篇关于安卓:试图启动BluetoothSettings活动强制关闭并抛出NullPointerException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 15:22