Issue
Now i want to use espresso to test my app ui, but when i use fresco library, as one SimpleDreweeView in xml, the espresso will be failed with errors:
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.facebook.drawee.view.SimpleDraweeView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)
at android.app.Activity.setContentView(Activity.java:2388)
at com.example.android.testing.espresso.intents.AdvancedSample.ImageViewerActivity.onCreate(ImageViewerActivity.java:45)
So anyone can help me to solve the problem?? Thanks a lot!!
My xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
tools:context=".ImageViewerActivity">
<Button android:id="@+id/button_take_photo"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_open_camera"
android:layout_gravity="center_horizontal"
android:onClick="onOpenCamera"
android:layout_marginTop="32dp"/>
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="128dp"
android:layout_height="128dp"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="32dp"
android:background="#ffdbdbdb"/>
</LinearLayout>
ImageViewActivity:
public class ImageViewerActivity extends Activity {
@VisibleForTesting
protected static final String KEY_IMAGE_DATA = "data";
private static final int REQUEST_IMAGE_CAPTURE = 1;
private SimpleDraweeView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_viewer);
mImageView = (SimpleDraweeView) findViewById(R.id.imageView);
}
private void dispatchTakePictureIntent() {
// Open the camera to take a photo.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
public void onOpenCamera(View view) {
dispatchTakePictureIntent();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// If an image is received, display it on the ImageView.
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
if (extras == null || !extras.containsKey(KEY_IMAGE_DATA)) {
return;
}
Bitmap imageBitmap = (Bitmap) extras.get(KEY_IMAGE_DATA);
mImageView.setImageBitmap(imageBitmap);
}
}
}
I just modify the google official demo, replace the imageview to simpledraweeview, and error prone ....
Solution
In your case writing
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
setContentView(R.layout.activity_image_viewer);
}
Answered By - Ratilal Chopda
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.