我在我的应用程序中使用2个数字选择器,它在3.2版本中...选择器在一个活动中调用警报...它们工作正常,直到我将主题更改为
android:theme="@style/android:Theme.DeviceDefault"
在我的活动清单中。在我添加此主题后,第一个选择器正在工作,第二个选择器无法工作...
etStrRatio.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AlertDialog.Builder imageDialog = new AlertDialog.Builder(KrazySettingsActivity.this);
LayoutInflater inflater = (LayoutInflater) KrazySettingsActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.krazypicker,
(ViewGroup) findViewById(R.id.nplayout));
hours = new String[331];
int j =-30;
for(int i=0; i<331; i++){
hours[i] = Integer.toString(j);
j++;
}
nphour = (NumberPicker)layout.findViewById(R.id.np);
nphour.setMaxValue(hours.length-1);
nphour.setMinValue(0);
nphour.setWrapSelectorWheel(true);
nphour.setDisplayedValues(hours);
imageDialog.setView(layout);
imageDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
etStrRatio.setText(hours[nphour.getValue()]);
valMinperHour = 60-Math.abs(60*100/(100+Integer.parseInt(hours[nphour.getValue()])));
Log.d("valMinperHour",Math.abs(valMinperHour)+"");
etStrMins.setText(Math.abs(valMinperHour)+"");
valKKHours = (float) (60-valMinperHour);
float cval = valKKHours/60;
valTotalHours = (float) 24/cval;
tvMin.setText(valKKHours+"");
tvHours.setText(valTotalHours+"");
/*valKKHours = (60-Math.abs(valMinperHour))/60;
Log.d("kkhours",Math.abs(valKKHours)+"");
//valTotalHours = 24/Math.abs(valKKHours);
etStrMins.setText(Math.abs(valMinperHour)+"");
tvMin.setText(valKKHours+"");
//tvHours.setText(valTotalHours+"");
*/ dialog.dismiss();
}
});
imageDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
imageDialog.create();
imageDialog.show();
}
});
etStrMins.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AlertDialog.Builder dialog = new AlertDialog.Builder(KrazySettingsActivity.this);
LayoutInflater inflater1 = (LayoutInflater) KrazySettingsActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout1 = inflater1.inflate(R.layout.krazypicker,
(ViewGroup) findViewById(R.id.nplayout));
mins = new String[331];
Log.d("beforefor","display");
for(int i=0; i<46; i++){
mins[i] = Integer.toString(i);
}
npmin = (NumberPicker)layout1.findViewById(R.id.np);
npmin.setMaxValue(mins.length-1);
npmin.setMinValue(0);
npmin.setWrapSelectorWheel(true);
npmin.setDisplayedValues(mins);
Log.d("before values","display");
dialog.setView(layout1);
dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
etStrMins.setText(mins[npmin.getValue()]);
valCompress = ((60*100)/(60-Integer.parseInt(mins[npmin.getValue()])))-100;
etStrRatio.setText((int)valCompress+"");
valKKHours = (float) (60-Integer.parseInt(mins[npmin.getValue()]));
float cval = valKKHours/60;
valTotalHours = (float) 24/cval;
tvMin.setText(valKKHours+"");
tvHours.setText(valTotalHours+"");
/*valMinperHour = 60-Math.abs(60*100/(100+Integer.parseInt(hours[nphour.getValue()])));
Log.d("valMinperHour",Math.abs(valMinperHour)+"");
etStrMins.setText(Math.abs(valMinperHour)+"");
valKKHours = (float) ((60-Math.abs(valMinperHour))/(60));
valTotalHours = (24/valKKHours);
tvMin.setText(valKKHours+"");
tvHours.setText(valTotalHours+"");
*/
dialog.dismiss();
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.create();
Log.d("create","display");
dialog.show();
Log.d("show","display");
}
});
我的Logcat是:
02-08 16:59:04.760: E/AndroidRuntime(671): FATAL EXCEPTION: main
02-08 16:59:04.760: E/AndroidRuntime(671): java.lang.NullPointerException
02-08 16:59:04.760: E/AndroidRuntime(671): at android.graphics.Canvas.drawText(Canvas.java:1368)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.widget.NumberPicker.onDraw(NumberPicker.java:1357)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.view.View.draw(View.java:11080)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.widget.NumberPicker.draw(NumberPicker.java:1313)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.view.ViewGroup.drawChild(ViewGroup.java:2885)
02-08 16:59:04.760: E/AndroidRuntime(671): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.drawChild(ViewGroup.java:2885) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.View.draw(View.java:10981) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.widget.FrameLayout.draw(FrameLayout.java:450) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.drawChild(ViewGroup.java:2887) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.drawChild(ViewGroup.java:2885) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.drawChild(ViewGroup.java:2885) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.drawChild(ViewGroup.java:2885) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.View.draw(View.java:10981) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.widget.FrameLayout.draw(FrameLayout.java:450) 02-08 16:59:04.760:E / AndroidRuntime(671):at com.android.internal.policy.impl.PhoneWindow $ DecorView.draw(PhoneWindow.java:2126) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewRootImpl.draw(ViewRootImpl.java:2026) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.os.Handler.dispatchMessage(Handler.java:99) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.os.Looper.loop(Looper.java:137) 02-08 16:59:04.760:E / AndroidRuntime(671):在android.app.ActivityThread.main(ActivityThread.java:4424) 02-08 16:59:04.760:E / AndroidRuntime(671):at java.lang.reflect.Method.invokeNative(Native Method) 02-08 16:59:04.760:E / AndroidRuntime(671):at java.lang.reflect.Method.invoke(Method.java:511) 02-08 16:59:04.760:E / AndroidRuntime(671):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784) 02-08 16:59:04.760:E / AndroidRuntime(671):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 02-08 16:59:04.760:E / AndroidRuntime(671):at dalvik.system.NativeStart.main(Native Method)