Hi all, Thanks 4 ur reply.
Actually I want to call some methods of one Activity (test.check.Test1.java) from another activity (my current activity) at runtime in the separate Thread. In the main GUI Thread this works fine. This Test1.java activity resides in the test.check.apk file which is stored in the /sdcard. This is simply activity class with only one function xyz() (which I want to call) and returns a String "Hellooo Man" as follows package test.check; import android.app.Activity; import android.os.Bundle; public class Test1 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public String xyz(){ return "Hellooo Man"; } }. But during the execution of this function from another activity (another .apk) at runtime in the separate Thread causes exception at this line "Object o = c.newInstance();" which I came to know during debugging , otherwise class is Loaded nicely and also loaded method xyz() without any problem. But to execute that method I need to create Obect instance and then Method.invoke(o); I hope u got it now. Dianne:: Exception race is as follows, 04-08 11:57:08.802: ERROR/AndroidRuntime(240): Uncaught handler: thread Thread-8 exiting due to uncaught exception 04-08 11:57:08.812: ERROR/AndroidRuntime(240): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 04-08 11:57:08.812: ERROR/AndroidRuntime(240): at android.os.Handler.<init>(Handler.java:111) 04-08 11:57:08.812: ERROR/AndroidRuntime(240): at android.app.Activity.<init>(Activity.java:660) 04-08 11:57:08.812: ERROR/AndroidRuntime(240): at test.check.Test1.<init>(Test1.java:6) 04-08 11:57:08.812: ERROR/AndroidRuntime(240): at java.lang.Class.newInstance(Native Method) 04-08 11:57:08.812: ERROR/AndroidRuntime(240): at android.giude.SocketFTP.SocketFTP.readTheFile(SocketFTP.java:128) 04-08 11:57:08.812: ERROR/AndroidRuntime(240): at android.giude.SocketFTP.SocketFTP$1.run(SocketFTP.java:50) Mariano : I have not used Looper.prepare(), Is it required?? If yes then where and how to define handler for that? On Apr 7, 10:20 pm, Dianne Hackborn <hack...@android.com> wrote: > Also you need to look at the exception stack trace. It will show you who is > trying to create a Handler. > > On Tue, Apr 7, 2009 at 9:44 AM, Streets Of Boston > <flyingdutc...@gmail.com>wrote: > > > > > > > > > But do you want a Looper and Handler in your thread 't'? > > Why do you load it in another thread? > > Are you planning in dispatching and handling messages in this thread > > 't'? > > > If not, don't start adding all this stuff just to make the run-time > > happy. > > > Put a breakpoint in your default constructor of your test.check.Test1 > > class and see which line of code needs a Handler or Looper. > > > What are you trying to accomplish? It looks like you're trying to load > > and construct a class from an APK (check.apk). Are you initializing an > > Activity from this APK called 'Test1'? If so, I understand why it may > > need a looper/handler. But if you're loading an Activity (Test1) > > within another Activity (the one trying to load check.apk), you may > > get into a heap of other trouble. But i'm not an expert on this at > > all. Google engineers will know much more about this. > > > On Apr 7, 10:55 am, Ask <asifk1...@gmail.com> wrote: > > > Hi Streets, > > > > I dont think this is the case. > > > > Same code executes nicely If I call that method in the onCreate() > > > method (i.e. main thread itself) > > > > problem occurs in the Object creation if I will call this method > > > readTheFile() in the Thread. > > > Can you give any info. regarding how I can define Looper and Handler > > > in my code to execute it without any error.??? > > > > On Apr 7, 7:00 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote: > > > > > 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-Hidequotedtext- > > > > > > > > - Show quoted text -- Hide quoted text - > > > > > > > - Show quoted text -- Hide quoted text - > > > > > > - Show quoted text -- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > -- > Dianne Hackborn > Android framework engineer > hack...@android.com > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them.- 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 -~----------~----~----~----~------~----~------~--~---