Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:03:28+00:00 2026-06-15T11:03:28+00:00

I get the following java.lang.IllegalArgumentException: View not attached to window manager this happens when

  • 0

I get the following “java.lang.IllegalArgumentException: View not attached to window manager“

this happens when the toast.show() is called.

Please any explanation? Thanks a lot!!!!

EDITED: I post all the code + the logcat

CODE – NOTE the error occurs when the toast.show() is invoked in the listener.

public class MainActivity extends Activity {
    private Gallery gal;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        String[] descrizione =    {"cani","boffo","gigo","belo","fyyfy","bogin","boginetti","zippe","ninne","cestino","cagnin    o","cucciolo",};
        ArrayList<Elementi> el = new ArrayList<Elementi>(10);
        int[] tabDrawables = new int[] {
                     R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img1,R.drawable.img4,R.drawable.    img5,R.drawable.img6,R.drawable.img7,R.drawable.img8,R.drawable.img9,R.drawable.img10};

        for (int numero =1; numero < 10;numero++) {
            ImageView imgm = new ImageView(this);
            imgm.setImageResource(tabDrawables[numero]);
            el.add(new Elementi(imgm,descrizione[numero])); 
            };  

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Gallery gal=(Gallery)findViewById(R.id.galleria);
        gal.setAdapter(new MyAdapter(el));
        gal.setOnItemClickListener(new MyListener(this));       

    }
public class MyAdapter extends ArrayAdapter<Elementi> {
        public MyAdapter(ArrayList<Elementi> list) {
        super(MainActivity.this, R.layout.row, list);}

    public View getView(int position, View convertView,ViewGroup parent) {
           View row= convertView;  
           if(row==null){
                LayoutInflater inflater = (LayoutInflater)     MainActivity.this.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
                row = inflater.inflate(R.layout.row, null);    
           }

                TextView txt =(TextView)row.findViewById(R.id.testorow);
                txt.setText(getItem(position).tx) ;
                ImageView ima =(ImageView)row.findViewById(R.id.immagine);
                ima.setImageDrawable(getItem(position).im.getDrawable());
                return row;};

}  


public class Elementi { 
public ImageView im;
public String tx;
public Elementi(ImageView img,String txt){
        im =img;
        tx = txt;       
    }
}

public class MyListener implements AdapterView.OnItemClickListener {
     private final Context mContext;
     public MyListener(Activity ctx) {
          mContext = ctx;
        }
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        Toast toast = new Toast(mContext);
        toast.setView(arg1);
        toast.show();

    }}

}

LOGCAT

11-30 17:26:35.421: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:35.440: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:35.440: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:35.681: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:35.681: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:35.961: D/dalvikvm(765): GC_CONCURRENT freed 270K, 14% free 2571K/2968K,     paused 18ms+3ms, total 56ms
11-30 17:26:35.961: D/dalvikvm(765): WAIT_FOR_CONCURRENT_GC blocked 38ms
11-30 17:26:36.131: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.140: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.140: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.241: D/dalvikvm(765): GC_CONCURRENT freed 239K, 12% free 2805K/3172K,     paused 21ms+8ms, total 64ms
11-30 17:26:36.261: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.301: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.331: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.341: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.371: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.371: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.391: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.391: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.400: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.400: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.421: D/gralloc_goldfish(765): Emulator without GPU emulation detected.
11-30 17:26:36.451: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:36.501: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.158: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.161: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.171: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.171: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.191: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.191: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.281: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.301: W/Trace(765): Unexpected value from nativeGetEnabledTags: 0
11-30 17:26:39.310: D/AndroidRuntime(765): Shutting down VM
11-30 17:26:39.310: W/dalvikvm(765): threadid=1: thread exiting with uncaught exception     (group=0x40a70930)
11-30 17:26:39.321: E/AndroidRuntime(765): FATAL EXCEPTION: main
11-30 17:26:39.321: E/AndroidRuntime(765): java.lang.IllegalArgumentException: View not     attached to window manager
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:383)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:285)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.widget.Toast$TN.handleShow(Toast.java:396)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.widget.Toast$TN$1.run(Toast.java:310)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.os.Handler.handleCallback(Handler.java:725)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.os.Handler.dispatchMessage(Handler.java:92)
11-30 17:26:39.321: E/AndroidRuntime(765):  at android.os.Looper.loop(Looper.java:137)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     android.app.ActivityThread.main(ActivityThread.java:5039)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     java.lang.reflect.Method.invokeNative(Native Method)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     java.lang.reflect.Method.invoke(Method.java:511)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-30 17:26:39.321: E/AndroidRuntime(765):  at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-30 17:26:39.321: E/AndroidRuntime(765):  at dalvik.system.NativeStart.main(Native     Method)
11-30 17:26:42.031: I/Process(765): Sending signal. PID: 765 SIG: 9
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:03:29+00:00Added an answer on June 15, 2026 at 11:03 am

    I think the problem lies in the code at this toast.setView(arg1); because the same view can’t not be attached to multiple objects. as this view is already attached to Gallery item.

    Update
    You just need to recreate that view by layoutInflator using the same values of the current view and then pass this new view to the Toast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following exception: java.lang.IllegalArgumentException: object is not an instance of the
I get the following exception java.lang.NumberFormatException: Invalid int: It is happening when you try
When trying to run a junit test I get the following error - java.lang.ClassCastException:
I am trying to put String[] in jsonObject and getting following error java.lang.IllegalArgumentException: Invalid
I get the following IOException : java.io.IOException: Access is denied at java.io.WinNTFileSystem.createFileExclusively(Native Method) at
Sometimes when I am inside my app, I get the following error : java.io.IOException:
How do I get the equivalent of the following Java code (initializing a SLF4J
I get the following error when I run a java program: Exception in thread
I get the following Exception running my app: java.net.SocketException: Permission denied (maybe missing INTERNET
I get the following error when running mongo-hadoop streaming: java.io.IOException: Cannot run program "mapper.py":

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.