2015-08-20 1 views
1

J'essaie de créer popup avec runnable mais je ne suis pas capable de. je reçois toujours « NULLPOINTEREXPEXTIONS » im presque fini avec mon application Android, la seule chose qui reste est de montrer pop-up après un certain temps, j'ai utilisé runnable montrer ici pop-upCréer un popup avec un thread exécutable Android

est mon code, erreur générer cette ligne

View layout = inflater.inflate(R.layout.popup_layout,(ViewGroup) findViewById(R.id.popup_element)); 

REMARQUE: popup_element est ID de mise en page popup fichier xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/popup_element" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#444444" 
android:orientation="vertical" 
android:padding="10sp" > 


public void run() { 
      //Do something after 100ms 
       initiatePopupWindow(); 
      } 

      private void initiatePopupWindow() { 
      try { 
      // We need to get the instance of the LayoutInflater 
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View layout = inflater.inflate(R.layout.popup_layout,(ViewGroup) findViewById(R.id.popup_element)); 
      pwindo = new PopupWindow(layout, 300, 370, true); 
      pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0); 

      Button btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup); 
      btnClosePopup.setOnClickListener(cancel_button_click_listener); 

      } catch (Exception e) { 
      e.printStackTrace(); 
      } 
     } 

      private OnClickListener cancel_button_click_listener = new OnClickListener() { 
      public void onClick(View v) { 

     pwindo.dismiss(); 

      } 
      }; 

     }, 700); 
     } 
    } 

eRREUR LOG

D/gralloc_goldfish(906): Emulator without GPU emulation detected. 
 
W/System.err(906): java.lang.NullPointerException 
 
W/System.err(906): \t at com.example.runnable_with_popup.MainActivity$1.initiatePopupWindow(MainActivity.java:43) 
 
W/System.err(906): \t at com.example.runnable_with_popup.MainActivity$1.run(MainActivity.java:34) 
 
W/System.err(906): \t at android.os.Handler.handleCallback(Handler.java:730) 
 
W/System.err(906): \t at android.os.Handler.dispatchMessage(Handler.java:92) 
 
W/System.err(906): \t at android.os.Looper.loop(Looper.java:137) 
 
W/System.err(906): \t at android.app.ActivityThread.main(ActivityThread.java:5103) 
 
W/System.err(906): \t at java.lang.reflect.Method.invokeNative(Native Method) 
 
W/System.err(906): \t at java.lang.reflect.Method.invoke(Method.java:525) 
 
W/System.err(906): \t at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
 
W/System.err(906): \t at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
 
W/System.err(906): \t at dalvik.system.NativeStart.main(Native Method)

S'il vous plaît aidez-moi de ce problème. J'ai cherché sur internet mais n'a pas trouvé par exemple ou une question liée à mon problème aide sera appréciée

grâce

+1

votre pile de publier une erreur – Sharj

+0

sûr, je vais poster mon chat Log, quand je vais revenir à la maison @Sharj –

+0

Journal des erreurs ajouté, Veuillez cocher @Sharj –

Répondre

2

Le parent pourrait manquer, mettez faux sur la dernière partie

View layout = inflater.inflate(R.layout.popup_layout,(ViewGroup) findViewById(R.id.popup_element),false); 
+0

la plupart du temps le gonflement avec le parent provoque nullpointer – Sheychan

+0

J'ai utilisé ** false ** mais cela ne fonctionne pas. aussi je m enregistrez le journal des erreurs, j'espère que vous pouvez trouver une meilleure solution @Sheychan –

+0

quel est le contexte? – Sheychan

0

utilisent ce un

View popupView = layoutInflater.inflate(R.layout.popup_layout, null);