I'm new to Android. My app is closing when running on real devices, but it is working fine on my simulator. This is error code that I'm getting on debugger. I'm trying to add an image slider with the help of pageViewer. The App was working fine before I added the slider.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.windows81.travelspoc, PID: 17409
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:545)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.example.windows81.travelspoc.ViewPagerAdapter.instantiateItem(ViewPagerAdapter.java:39)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1002)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1150)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1084)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
at android.view.View.measure(View.java:19141)
at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:934)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:973)
at android.view.View.measure(View.java:19141)
at android.support.v4.widget.NestedScrollView.measureChildWithMargins(NestedScrollView.java:1446)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.support.v4.widget.NestedScrollView.onMeasure(NestedScrollView.java:512)
at android.view.View.measure(View.java:19141)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:19141)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6245)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:400)
at android.view.View.measure(View.java:19141)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.view.View.measure(View.java:19141)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6245)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
at android.view.View.measure(View.java:19141)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2790)
at android.view.View.measure(View.java:19141)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2476)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1440)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1694)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6748)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:713)
at android.view.Choreographer.doFrame(Choreographer.java:648)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5790)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1015)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:827)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:880)
at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at andro
I/Process: Sending signal. PID: 17409 SIG: 9
Disconnected from the target VM, address: 'localhost:8600', transport:
'socket'
HomeActivity.java
package com.example.windows81.travelspoc;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class HomeActivity extends AppCompatActivity {
ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
viewPager = (ViewPager) findViewById(R.id.viewPager);
ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(this);
viewPager.setAdapter(viewPagerAdapter);
}
public void exploreActivity(View view){
Intent intent = new Intent(this,ExploreActivity.class);
startActivity(intent);
}
public void packagesActivity(View view){
Intent intent = new Intent(this,PackagesActivity.class);
startActivity(intent);
}
public void dealsActivity(View view){
Intent intent = new Intent(this,DealsActivity.class);
startActivity(intent);
}
}
ViewPagerAdapter.java
package com.example.windows81.travelspoc;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
/**
* Created by Windows 8.1 on 11/6/2017.
*/
public class ViewPagerAdapter extends PagerAdapter{
private Context context;
private LayoutInflater layoutInflater;
private Integer [] images = {R.drawable.slide1,R.drawable.slide2};
public ViewPagerAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
return images.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.custom_layout,null);
ImageView imageView = (ImageView) view.findViewById(R.id.slider);
imageView.setImageResource(images[position]);
ViewPager vp = (ViewPager) container;
vp.addView(view, 0);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
ViewPager vp = (ViewPager) container;
View view = (View) object;
vp.removeView(view);
}
}
Stack trace may be misleading. There might be a problem with your drawable. Try a different @drawable and see if it works. Or other one may be your image file size are little big
Your error is:
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
Check this and search by this.