0

我正在尝试onCreate使用以下代码在服务中布局 Inflate:

// ...
public void onCreate() {    
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    call = new PhoneCall();

    IntentFilter intentFilter = new IntentFilter(outgoingIntent);
    registerReceiver(callReceiver, intentFilter);

    final LayoutInflater myInflator = (LayoutInflater) ctext.getSystemService(Context.LAYOUT_INFLATER_SERVICE );        

    onPhoneStatelistener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

// ...

这是我的日志猫:

04-22 02:38:35.324: E/AndroidRuntime(28837): FATAL EXCEPTION: main
04-22 02:38:35.324: E/AndroidRuntime(28837): java.lang.RuntimeException: Unable to create service com.castello.AllMyCalls.CallService: java.lang.NullPointerException
04-22 02:38:35.324: E/AndroidRuntime(28837):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1959)
04-22 02:38:35.324: E/AndroidRuntime(28837):    at android.app.ActivityThread.access$2500(ActivityThread.java:117)
04-22 02:38:35.324: E/AndroidRuntime(28837):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)

我只是收到“空指针”错误。有什么建议么?

4

1 回答 1

0

当我尝试LayoutInflater服务时,我通常会这样做:

LayoutInflater inflater = LayoutInflater.from(Context);

希望这可能对你有用!

于 2013-04-22T01:51:23.633 回答