저는 안드로이드 개발에 다소 익숙합니다. 이것은 처음으로 환경 설정 화면에 설치된 응용 프로그램 목록을 제공하려고 시도한 것입니다. 이 목록에서 선택한 값은 나중에 사용자가 선택한 앱을 실행하는 데 사용됩니다. 이것은 다음과 같은 XML 내 PreferenceScreen에 추가됩니다Android : 설치된 애플리케이션으로 ListPreference 채우기?
public class AppSelectorPreference extends ListPreference {
public AppSelectorPreference(Context context, AttributeSet attrs) {
super(context,attrs);
PackageManager pm = context.getPackageManager();
List<PackageInfo> appListInfo = pm.getInstalledPackages(0);
CharSequence[] entries = new CharSequence[appListInfo.size()];
CharSequence[] entryValues = new CharSequence[appListInfo.size()];
try {
int i = 0;
for (PackageInfo p : appListInfo) {
if (p.applicationInfo.uid > 10000) {
entries[i] = p.applicationInfo.loadLabel(pm).toString();
entryValues[i] = p.applicationInfo.packageName.toString();
Log.d(BT,"Label: " + entries[i]);
Log.d(BT,"PName: " + entryValues[i]);
i++;
}
}
} catch (Exception e) {
Log.e(BT,"ER> Put descriptive error message here");
e.printStackTrace();
}
setEntries(entries);
setEntryValues(entryValues);
}
}
:
나는 다음과 같은 클래스를 만들었습니다
모든 것이 AppSelectorPreference, 클릭 할 때까지 제대로 작동 표시 <PreferenceCategory android:title="Launch Application">
<CheckBoxPreference
android:title="Launch Application"
android:summary="Launch an application"
android:defaultValue="false"
android:key="pref_connect_launch_enable"
android:dependency="pref_connect_enable"/>
<com.nirsoftware.AppSelectorPreference
android:title="Select Application"
android:summary="Select application to launch"
android:key="pref_connect_package_name"
android:dependency="pref_connect_launch_enable"/>
</PreferenceCategory>
하는 android.preference.ListPreference.findIndexOfValue (ListPreference.java:169)에 NPE를 던집니다. 어떤 제안?
내가 무엇인지 알고 싶어에게 명령을 null 항목을 실행할 수 없습니다 거짓 때문에 널 포인터 오류가 발생 무엇 원인의 경우 조건을 제거 할 제안 오류는 내 응용 프로그램 외부, 나는 ListPreference.java OS의 일부라고 생각합니다. 나는 파기해야하고 그 방법에서 무슨 일이 벌어지고 있는지보아야한다. –