android - Why I can't show image inside custom dialog? -


I want to make some kind of logging process in my Android app. I have figured out how the user is pressing (three times) on the screen and creating logging sequence from it. Finally, I want to show 3 images that represent the selected logging sequence (from my dosing folder)

I have set dynamically a drable ID and when I place an image on the main layout, Works. But if I put an image inside a custom dialogue, then I get the strength. From LogCat I see the following: at java.lang.NullPointerException image1.setImageResource (iIdSlike);

If I show drawable identification letters as a text it is ok

  image1.setImageResource (free and only on ID main and custom dialog layout  

I got the force even though I established the image (not dynamic) like .drawable.s11);

Why can not I show an image on custom dialogue?

This is my dijalog.xml (custom dialog layout):

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" & gt; & Lt; imageView android: id = "@ + id / imgDrugi" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignRight = "@ + id / TextView01" Android: layout_below = "@ + id / TextView01" Android: Layout_margin = "27dp" Android: layout_marginopop = "51dp" /> & Lt; Button android: id = "@ + id / Button1" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: layout_alignParentBottom = "true" Android: layout_alignParentRight = "true" android: text = "button" / & gt ; & Lt; Android: layout_alignParentTop = "true" Android: layout_centerHorizontal = "true" Android: layout_marginTop = "118dp" Android: text = "@ + id / textView01" android: layout_width = "wrap_content" android: layout_height = "wrap_content" = "@ + ID / Text View" /> & Lt; / RelativeLayout & gt;   

And this is my code:

  public class MyWorkLogiranje extends implements activity OnClickListener {@Override public boolean onTouchEvent (MotionEvent event) {switch ( Event.getAction ()) {Case MotionEvent.ACTION_DOWN :. . . // String to obtain SPV calculation = s31 = "s31"; // test purposes manually // image and core layout (it works) iIdSlike = getResources (set text) sPrvi getIdentifier (sPrvi, "drawable", getPackageName (for)). Image Image = (ImageView) findViewById (R.id.imgPrvi); Image.setImageResource (iIdSlike); TextView text1 = (TextView) findViewById (R.id.txtPrvi); Text1.setText ("iIdSlike:" + iIdSlike); // PriyoSJLog Last Dialogue Dialogue = New Dialogue (MyWorks LoginThis); Dialog.setContentView (R.layout.dijalog); Dialog.setTitle ("This is my custom dialog box"); Dialog.setCancelable (true); Dialog.getContext (); TextViewText = (TextView) dialog.findViewById (R.id.TextView01); Text.setText ("iIdSlike:" + iIdSlike); ImageView image1 = (ImageView) findViewById (R.id.imgDrugi); Image1.setImageResource (R.drawable.iIdSlike); //image1.setImageResource (R.drawable.s11); // podabajaji dagetta button button = (button) dialog.findViewById (R.id.button1); Button.setOnClickListener (New OnClickListener () {@Override Click Public Zero (see V) {dialog.dismiss ();}}); Dialog.show ();   

Can anyone help me with this? I am scratching my head for about two days in this. Thank you

Your findViewById is failing. So you are getting NullPointerException

  imageView Image1 = (imageView) findViewById (R.id.imgDrugi).   

should be

  imageView Image1 = (imageView) dialog.findViewById (R.id.imgDrugi);    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -