Android Custom Carrier Label nullpointerexception
<p>I've added AOKP's Custom Carrier Label options to my rom and everything works with the exception of getting a Settings fc when OK is clicked in the dialog window...The customlabeltextsummary is updated correctly and the carrier is changed as it should be...</p>

<p>Settings.java :</p>

<pre><code>package com.android.settings.cyanogenmod;

import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.view.IWindowManager;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceChangeListener;
import android.provider.Settings;
import android.text.Spannable;
import android.util.Log;
import android.view.IWindowManager;
import android.view.Display;
import android.view.LayoutInflater;
import android.widget.EditText;

import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SystemSettings extends SettingsPreferenceFragment implements
    Preference.OnPreferenceChangeListener{

private static final String TAG = "SystemSettings";

private static final String KEY_POWER_BUTTON_TORCH = "power_button_torch";

private CheckBoxPreference mPowerButtonTorch;
private static final String KEY_CHRONUS = "chronus";
private static final String PREF_FORCE_DUAL_PANEL = "force_dualpanel";
private static final String PREF_CUSTOM_CARRIER_LABEL = "custom_carrier_label";

Preference mCustomLabel;

Context mContext;

String mCustomLabelText = null;

CheckBoxPreference mDualpane;
private boolean torchSupported() {
    return getResources().getBoolean(R.bool.has_led_flash);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.system_settings);

    mCustomLabel = findPreference(PREF_CUSTOM_CARRIER_LABEL);
    updateCustomLabelTextSummary();

    // Dont display the lock clock preference if its not installed
    removePreferenceIfPackageNotInstalled(findPreference(KEY_CHRONUS));

    mPowerButtonTorch = (CheckBoxPreference) findPreference(KEY_POWER_BUTTON_TORCH);
    if (torchSupported()) {
        mPowerButtonTorch.setChecked((Settings.System.getInt(getActivity().
                getApplicationContext().getContentResolver(),
                Settings.System.POWER_BUTTON_TORCH, 0) == 1));
    } else {
        getPreferenceScreen().removePreference(mPowerButtonTorch);
    }

    mDualpane = (CheckBoxPreference) findPreference(PREF_FORCE_DUAL_PANEL);
        mDualpane.setOnPreferenceChangeListener(this);

}

@Override
public void onResume() {
    super.onResume();
}

@Override
public void onPause() {
    super.onPause();
}

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference == mPowerButtonTorch) {
        boolean enabled = mPowerButtonTorch.isChecked();
        Settings.System.putInt(getContentResolver(), Settings.System.POWER_BUTTON_TORCH,
                enabled ? 1 : 0);
        return true;
    } else if (preference == mCustomLabel) {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

        alert.setTitle(R.string.custom_carrier_label_title);
        alert.setMessage(R.string.custom_carrier_label_explain);

        // Set an EditText view to get user input
        final EditText input = new EditText(getActivity());
        input.setText(mCustomLabelText != null ? mCustomLabelText : "");

        alert.setView(input);
        alert.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                String value = ((Spannable) input.getText()).toString();
                Settings.System.putString(getActivity().getContentResolver(),
                        Settings.System.CUSTOM_CARRIER_LABEL, value);
                updateCustomLabelTextSummary();
                Intent i = new Intent();
                i.setAction("com.android.settings.LABEL_CHANGED");
                mContext.sendBroadcast(i);
            }
        });

        alert.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
            }
        });

        alert.show();   
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
}

public boolean onPreferenceChange(Preference preference, Object objValue) {
    ContentResolver cr = getActivity().getContentResolver();

    if (preference == mDualpane) {
        Settings.System.putInt(getActivity().getContentResolver(),
                Settings.System.FORCE_DUAL_PANEL,
                ((CheckBoxPreference)preference).isChecked() ? 0 : 1);
        return true;
    }
    return false;
}

private boolean removePreferenceIfPackageNotInstalled(Preference preference) {
    String intentUri=((PreferenceScreen) preference).getIntent().toUri(1);
    Pattern pattern = Pattern.compile("component=([^/]+)/");
    Matcher matcher = pattern.matcher(intentUri);

    String packageName=matcher.find()?matcher.group(1):null;
    if(packageName != null) {
        try {
            getPackageManager().getPackageInfo(packageName, 0);
        } catch (NameNotFoundException e) {
            Log.e(TAG,"package "+packageName+" not installed, hiding preference.");
            getPreferenceScreen().removePreference(preference);
            return true;
        }
    }
    return false;
}

private void updateCustomLabelTextSummary() {
    mCustomLabelText = Settings.System.getString(getActivity().getContentResolver(),
            Settings.System.CUSTOM_CARRIER_LABEL);
    if (mCustomLabelText == null || mCustomLabelText.length() == 0) {
        mCustomLabel.setSummary(R.string.custom_carrier_label_notset);
    } else {
        mCustomLabel.setSummary(mCustomLabelText);
    }
}   
</code></pre>

<p>}</p>

<p>logcat :</p>

<pre><code>W/System.err(13551): Removed 2131231241
W/System.err(13551): Removed 2131231255
D/dalvikvm( 3528): GC_CONCURRENT freed 384K, 16% free 2993K/3552K, paused 2ms+4ms, total 33ms
D/dalvikvm(13551): GC_CONCURRENT freed 190K, 10% free 3282K/3644K, paused 2ms+8ms, total   37ms
D/AndroidRuntime(13551): Shutting down VM
W/dalvikvm(13551): threadid=1: thread exiting with uncaught exception (group=0x40d12600)
E/AndroidRuntime(13551): FATAL EXCEPTION: main
E/AndroidRuntime(13551): java.lang.NullPointerException
E/AndroidRuntime(13551):    at com.android.settings.cyanogenmod.SystemSettings$1.onClick(SystemSettings.java:143)
E/AndroidRuntime(13551):    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
E/AndroidRuntime(13551):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13551):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(13551):    at android.app.ActivityThread.main(ActivityThread.java:5191)
E/AndroidRuntime(13551):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13551):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(13551):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/AndroidRuntime(13551):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/AndroidRuntime(13551):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 1108):   Force finishing activity com.android.settings/.SubSettings
W/ActivityManager( 1108): Activity pause timeout for ActivityRecord{40ff74b8 u0 com.android.settings/.SubSettings}
D/dalvikvm(13124): GC_FOR_ALLOC freed 411K, 22% free 3616K/4608K, paused 28ms, total 34ms
I/Process (13551): Sending signal. PID: 13551 SIG: 9
W/InputDispatcher( 1108): channel '41188140 com.android.settings/com.android.settings.SubSettings (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
I/WindowState( 1108): WIN DEATH: Window{41369d90 u0 com.android.settings/com.android.settings.SubSettings}
I/ActivityManager( 1108): Process com.android.settings (pid 13551) has died.
E/InputDispatcher( 1108): channel '41188140 com.android.settings/com.android.settings.SubSettings (server)' ~ Channel is unrecoverably broken and will be disposed!
W/InputDispatcher( 1108): channel '40ffd998 com.android.settings/com.android.settings.Settings (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
E/InputDispatcher( 1108): channel '40ffd998 com.android.settings/com.android.settings.Settings (server)' ~ Channel is unrecoverably broken and will be disposed!
W/InputDispatcher( 1108): Attempted to unregister already unregistered input channel '41188140 com.android.settings/com.android.settings.SubSettings (server)'
W/InputDispatcher( 1108): Attempted to unregister already unregistered input channel '40ffd998 com.android.settings/com.android.settings.Settings (server)'
I/WindowState( 1108): WIN DEATH: Window{41188140 u0 com.android.settings/com.android.settings.SubSettings}
I/WindowState( 1108): WIN DEATH: Window{40ffd998 u0 com.android.settings/com.android.settings.Settings}
I/ActivityManager( 1108): Start proc com.android.settings for activity com.android.settings/.Settings: pid=13575 uid=1000 gids={41000, 1015, 1028, 3002, 3001, 3003, 3007}
W/WindowManager( 1108): Rebuild removed 7 windows but added 6
W/WindowManager( 1108): This window was lost: Window{41369d90 u0 com.android.settings/com.android.settings.SubSettings EXITING}
W/WindowManager( 1108): mDisplayId=0 mSession=Session{41e7d3b0 13551:1000} mClient=android.os.BinderProxy@4108dde8
</code></pre>

<p>line 143 is as follows :</p>

<pre><code>mContext.sendBroadcast(i);
</code></pre>

<p>anyone got an idea whats going on here?</p>
