0

我创建了一个简单的项目来在模拟器上启动 facebook 应用程序。程序运行时显示以下错误测试运行失败: Instrumentation run failed due to 'java.lang.ClassNotFoundException

代码是 fb.java 文件

  package com.facebook.katana;

  import junit.framework.Assert;
  import com.jayway.android.robotium.solo.Solo;
  //import junit.framework.Assert;
  import android.test.ActivityInstrumentationTestCase2;

   @SuppressWarnings("rawtypes")
   public class fb extends ActivityInstrumentationTestCase2{

     private Solo solo;
     private static final String TARGET_PACKAGE_ID ="com.facebook.katana";  
     private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.facebook.katana.LoginActivity";    
     private static Class<?> launcherActivityClass; 
     static{    
         try{   
             launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);   
         } catch(ClassNotFoundException e) {    
             throw new RuntimeException(e); 
         }  
     }  

    @SuppressWarnings({ "unchecked", "deprecation" })
    public fb() {
        super(TARGET_PACKAGE_ID, launcherActivityClass);
        // TODO Auto-generated constructor stub
      }

   @Override
   protected void setUp() throws Exception{ 
       solo = new Solo(getInstrumentation(), getActivity());
   }    

   public void testCanOpenSettings() throws InterruptedException{   

           // wait for the specified time
       solo.sleep(3000);

       solo.clearEditText(0);

       solo.enterText(0, "abc@abc");
       // wait for the specified time 
       solo.sleep(3000);

      solo.enterText(1, "acd");

      solo.sleep(3000);

   }

   private boolean assertTrue(Object clickOnImage) {
       // TODO Auto-generated method stub
       return false;
   }

   @Override
   public void tearDown() throws Exception{ 
       try{ 
       solo.finalize(); 
       } catch(Throwable e) {   
           e.printStackTrace(); 
       }    
       getActivity().finish();  
       super.tearDown();        
   }  
}

清单。xml 文件 (FB2 Manifest.xml)

    <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.facebook.katana.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="18" />

   <instrumentation
       android:name="android.test.InstrumentationTestRunner"
       android:targetPackage="com.facebook.katana" />
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
      android:icon="@drawable/ic_launcher"
       android:label="@string/app_name" >
      <uses-library android:name="android.test.runner" />
    </application>

  </manifest>

请帮助解决此问题

4

1 回答 1

1

指定的 LAUNCHER ACTIVITY FULL CLASS NAME 不正确。一旦将其设置为正确的活动名称,程序执行就成功了。

于 2013-10-12T01:19:06.280 回答