2013-10-14 70 views
0

我正在製作一個程序,其中在彈出窗口中有一個微調框,但當單擊微調框時會出現錯誤並退出應用程序,明白,請我絕望了,我需要你的幫助,非常感謝你事先=)在彈出窗口中單擊微調框時出錯

public void añadirRegistro(View v){ 

    showPopup(leer_registros.this); 
} 
private void showPopup(final Activity context) { 

     Spinner eleccionIP,eleccionRegistro; 
     borrar_datos BorrarDatos = new borrar_datos(); 
     // Inflate the popup_layout.xml 
     RelativeLayout viewGroup = (RelativeLayout) context.findViewById(R.id.popup); 
     LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = layoutInflater.inflate(R.layout.popup_elegir_registros, viewGroup); 
     eleccionIP = (Spinner) layout.findViewById(R.id.popupIP); 
     eleccionRegistro = (Spinner)layout.findViewById(R.id.popupRegistro); 



     /*Cursor cur=BorrarDatos.obtenerIP(); 
     BorrarDatos.rellenarSpinner(cur,eleccionIP);*/ 


     final PopupWindow popup = new PopupWindow(context); 
     popup.setContentView(layout); 
     popup.setWidth(LayoutParams.WRAP_CONTENT); 
     popup.setHeight(LayoutParams.WRAP_CONTENT); 
     popup.setFocusable(true); 

     popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200, 200); 


     ArrayAdapter <CharSequence> adapter = new ArrayAdapter <CharSequence> (context, android.R.layout.simple_spinner_item); 
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

     adapter.add("item 1"); 
     adapter.add("item 2"); 
     eleccionIP.setAdapter(adapter); 


} 

在logcat的告訴我什麼,我只直接跳轉到調試,它告訴我:

Thread [<1> main] (Suspended (exception WindowManager$BadTokenException)) 
    <VM does not provide monitor information> 
    WindowManagerGlobal.addView(View, ViewGroup$LayoutParams, Display, Window) line: 255  
    WindowManagerImpl.addView(View, ViewGroup$LayoutParams) line: 69  
    PopupWindow.invokePopup(WindowManager$LayoutParams) line: 993 
    PopupWindow.showAsDropDown(View, int, int) line: 899  
    Spinner$DropdownPopup(ListPopupWindow).show() line: 603 
    Spinner$DropdownPopup.show() line: 981 
    Spinner.performClick() line: 609  
    View$PerformClick.run() line: 17355 
    Handler.handleCallback(Message) line: 725 
    ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 92 
    Looper.loop() line: 137 
    ActivityThread.main(String[]) line: 5041  
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
    Method.invoke(Object, Object...) line: 511 
    ZygoteInit$MethodAndArgsCaller.run() line: 793 
    ZygoteInit.main(String[]) line: 560 
    NativeStart.main(String[]) line: not available [native method] 
+0

POST錯誤日誌,請 –

+0

'setContenView();?' – RobinHood

+0

你能更清楚了嗎? – Isma9

回答

0

您似乎忘了將您的視圖設置爲內容。

View layout = layoutInflater.inflate(R.layout.popup_elegir_registros, viewGroup); 
this.setContentView(layout); 

Reference link: Stackoverflow Answer

+0

如果我做你告訴我也給我錯誤,但這次不顯示我彈出 – Isma9

+0

不幫助該參考鏈接? – RobinHood

+0

不,我沒有工作,仍然給我同樣的錯誤=(我很絕望! – Isma9

相關問題