我的 Android 应用程序出现错误。我有一个LineaArticulo
动态类,可以用标签形成一条线,编辑文本,一个按钮和微调器,拧紧微调器我得到一个错误,在这里附加了类构造函数。
所有数据都是正确的。
这里只是放置微调框。
public LineaArticulo(RelativeLayout layoutactual, final String[] Casos, Context context, int Xspinner, int Yspinner){
final Spinner spiner = new Spinner(context);
ArrayAdapter<String> adaptador =
new ArrayAdapter<String>(context,
android.R.layout.simple_spinner_item, Casos);
adaptador.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spiner.setAdapter(adaptador);
RelativeLayout.LayoutParams paramSpiner = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramSpiner.leftMargin = Xspinner; // Your X coordinate
paramSpiner.topMargin = Yspinner; // Your Y coordinate
spiner.setLayoutParams(paramSpiner);
layoutactual.addView(spiner);
}
错误:
06-04 16:02:02.021 961-961/compra.online.mercavalencia E/AndroidRuntime: FATAL EXCEPTION: main
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRoot.setView(ViewRoot.java:531)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.app.Dialog.show(Dialog.java:241)
at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
at android.widget.Spinner.performClick(Spinner.java:260)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)