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. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---