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が表示されます。自分のビューが存在するかどうかを判断する方法は他にありますか? –
solo.getViews()。size()を実行するとどうなりますか? – Renas
返品は14です。 –