It could be that during the construction of class test.check.Test1, a
Handler or something similar (i.e. something needing the main-thread's
message-queue) is constructed. Look at your test.check.Test1
implementation and see if this is the case.

If this is the case, you will get an exception if the constructor of
test.check.Test1 is executed on any other thread than the main-thread
with the message queue.

You would have gotten the same exception if you would have called 'new
test.check.Test1()'.

On Apr 7, 9:17 am, Ask <asifk1...@gmail.com> wrote:
> Is there any handler needed for that?? Any Idea???
>
> On Apr 7, 3:58 pm, Ask <asifk1...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I am using Reflection APIs in the background thread to call a method
> > dynamically from another application but I am getting the Exception:
>
> > "java.lang.RuntimeException: Can't create handler inside thread that
> > has not called Looper.prepare() "
>
> > at a line : Object o = c.newInstance();
>
> > my code in the Thread is as follows,
> > onCreate
>
> > public void onCreate(Bundle icicle) {
> >         super.onCreate(icicle);
> >         setContentView(R.layout.main);
>
> >         hh_text = (TextView)findViewById(R.id.server_start);
>
> >         Thread t = new Thread()
> >                 {
> >             public void run()
> >             {
> >                 readTheFile();
>
> >             }
>
> >                 };
> >                 t.start();
> >             }
>
> > public void readTheFile() {
> >         try {
>
> >                  PathClassLoader loader = new PathClassLoader( "/sdcard/
> > test.check.apk", ClassLoader.getSystemClassLoader());
> >                                  Class c = null;
>
> >                  c = loader.loadClass("test.check.Test1");
>
> >               Log.i("See"," Test Class Found ....");
>
> >               Method method = c.getMethod("xyz", null);
>
> >               Object o = c.newInstance();  // This line throws exception
> >               String s = (String) method.invoke(o);
> >               Log.i("See","Got method: " + s);
> >              } catch (Exception e) {
> >                         // TODO Auto-generated catch block
> >                         e.printStackTrace();
> >                 }     }
>
> > Please help.. If you know the issue.
>
> > On Apr 6, 7:14 pm, Ask <asifk1...@gmail.com> wrote:
>
> > > Thanx Mark for your quick reply. I will try it out and get back
>
> > > On Apr 6, 6:49 pm, Mark Murphy <mmur...@commonsware.com> wrote:
>
> > > > Asif k wrote:
> > > > >    But in my case, I am getting all 3 messages at a time after
> > > > > activity execution completed.
>
> > > > That is probably because you are doing long-running work on the UI 
> > > > thread.
>
> > > > > Is there any API available, using which
> > > > > I can show the status during the execution also.
>
> > > > Anything long-running should be in a background thread, in the activity
> > > > or wrapped in a service. Then, use Handler or runOnUiThread() or
> > > > something so the background thread can have the UI thread update your
> > > > TextView.
>
> > > > --
> > > > Mark Murphy (a Commons 
> > > > Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> > > > Android App Developer 
> > > > Training:http://commonsware.com/training.html-Hidequoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to