Is there any handler needed for that?? Any Idea???
On Apr 7, 3:58 pm, Ask <[email protected]> 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 <[email protected]> wrote:
>
>
>
> > Thanx Mark for your quick reply. I will try it out and get back
>
> > On Apr 6, 6:49 pm, Mark Murphy <[email protected]> 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-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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---