我正在嘗試使用Robotium截取我的Android應用程序,我正在使用以下功能,我發現here。Android,Robotium - 發佈截圖
public static String SCREEN_SHOTS_LOCATION="/sdcard/";
public static void takeScreenShot(View view, String name) throws Exception
{
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try
{
File sddir = new File(SCREEN_SHOTS_LOCATION);
if (!sddir.exists())
{
sddir.mkdirs();
}
fos = new FileOutputStream(SCREEN_SHOTS_LOCATION + name + "_" + System.currentTimeMillis() + ".jpg");
if (fos != null)
{
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
}
}
catch (Exception e)
{
}
}
我打電話就這樣從我的測試:
takeScreenShot(solo.getView(0), "Test");
當我調用該函數,我得到一個NullPointerException上線,它看起來我好像觀爲null。
我也使用
solo.getViews()審判;
並循環瀏覽每個視圖並截取屏幕截圖,但是我也得到一個NullPointerException。
ArrayList views = solo.getViews();
for(int i=0; i < views.size(); i++)
{
takeScreenShot(solo.getView(i), "Test");
}
我使用Robotium已經夠新到Android & Android的測試自動化,有誰能夠給我調試這些建議,或者爲什麼觀點似乎爲空,我的屏幕捕獲不工作的原因是什麼?
TIA。
更新
Error in testUI:
java.lang.NullPointerException
at com.myapp.test.UITests.testUI(UITests.java:117)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
我已經嘗試過這種方式還可以,但我還是看到被我稱之爲takeScreenShot行NullPointerException異常。任何其他方式我可以確定我的視圖是否存在? – 2012-01-12 13:17:30
如果你做了一個solo.getViews()。size(),你會得到什麼? – Renas 2012-01-12 13:32:56
返回14. – 2012-01-12 14:08:20