As the error says, you are calling peformClick() for a different thread than the UI thread (here the instrumentation thread). You can use the Instrumentation API to perform a call on the UI thread.
On Mon, Aug 24, 2009 at 6:08 PM, [email protected] < [email protected]> wrote: > > no one know it? > > On Aug 24, 11:01 am, "[email protected]" > <[email protected]> wrote: > > I am using ActivityInstrumentationTestCase2 to do some test for an > > activity. > > I get a button in the setUp() method like this: > > protected void setUp() throws Exception { > > super.setUp(); > > act = getActivity(); > > ........ > > btn = (Button)act.findViewById( R.id.bike_button ); // this > > button has been defined in layout > > } > > Then I use this button to perform a click in a test method like this: > > public void testBikeButton(){ > > //click the bike button > > btn.performClick(); > > ......} > > > > When run it as android junit, there will be an error like this: > > "android.view.ViewRoot$CalledFromWrongThreadException: Only the > > original thread that created a view hierarchy can touch its views. > > at android.view.ViewRoot.checkThread(ViewRoot.java:2440) > > at android.view.ViewRoot.playSoundEffect(ViewRoot.java:2261) > > at android.view.View.playSoundEffect(View.java:7457) > > at android.view.View.performClick(View.java:2178) > > at com.liufeng.vehicle.test.BikeTests.testBikeButton(BikeTests.java: > > 40) > > at java.lang.reflect.Method.invokeNative(Native Method) > > at android.test.InstrumentationTestCase.runMethod > > (InstrumentationTestCase.java:191) > > at android.test.InstrumentationTestCase.runTest > > (InstrumentationTestCase.java:181) > > at android.test.ActivityInstrumentationTestCase2.runTest > > (ActivityInstrumentationTestCase2.java:175) > > at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164) > > at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151) > > at android.test.InstrumentationTestRunner.onStart > > (InstrumentationTestRunner.java:418) > > at android.app.Instrumentation$InstrumentationThread.run > > (Instrumentation.java:1520)" > > > > How do I fix it? > > > -- Dianne Hackborn Android framework engineer [email protected] 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 [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 -~----------~----~----~----~------~----~------~--~---

