v7 support 23.0.1 crash: AppCompatButton.setBackgroundDrawable - android

I am experiencing this crash, with support library 23.0.1
It happens when showing a Dialog Fragment.
It verifies with both android.support.v4.app.DialogFragment and android.support.v7.app.AppCompatDialogFragment
Anyone else is experiencing this?
It always happens with release compilation (which has Proguard enabled), and only in some cases with debug compilation.
I am reporting the crash stacks for both fragment classes.
stack for android.support.v4.app.DialogFragment:
android.view.InflateException: Binary XML file line #115: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at com.android.internal.app.AlertController.installContent(AlertController.java:235)
at android.app.AlertDialog.onCreate(AlertDialog.java:356)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at android.support.v4.app.DialogFragment.onStart(SourceFile:406)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1060)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.o.a()' on a null object reference
at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(SourceFile:85)
at android.view.View.setBackground(View.java:16226)
at android.view.View.(View.java:4103)
at android.widget.TextView.(TextView.java:637)
at android.widget.Button.(Button.java:111)
at android.widget.Button.(Button.java:107)
at android.support.v7.widget.AppCompatButton.(SourceFile:64)
at android.support.v7.widget.AppCompatButton.(SourceFile:60)
at android.support.v7.internal.app.AppCompatViewInflater.createView(SourceFile:101)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:966)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at com.android.internal.app.AlertController.installContent(AlertController.java:235)
at android.app.AlertDialog.onCreate(AlertDialog.java:356)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at android.support.v4.app.DialogFragment.onStart(SourceFile:406)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1060)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
stack for android.support.v7.app.AppCompatDialogFragment:
android.view.InflateException: Binary XML file line #29: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at eu.baroncelli.oraritrenitalia.mainactivity.AlertDialogFragment.onCreateView(SourceFile:62)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1026)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.o.a()' on a null object reference
at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(SourceFile:85)
at android.view.View.setBackground(View.java:16226)
at android.view.View.(View.java:4103)
at android.widget.TextView.(TextView.java:637)
at android.widget.Button.(Button.java:111)
at android.widget.Button.(Button.java:107)
at android.support.v7.widget.AppCompatButton.(SourceFile:64)
at android.support.v7.widget.AppCompatButton.(SourceFile:60)
at android.support.v7.internal.app.AppCompatViewInflater.createView(SourceFile:101)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:966)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at eu.baroncelli.oraritrenitalia.mainactivity.AlertDialogFragment.onCreateView(SourceFile:62)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1026)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

According to this your proguard setup should contain the following rules if you're using appcompat-v7:
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
This will also save you from trouble when using SearchView and other things I imagine.

Related

getting InflateException when Clicking on Pay Button Payfort PaymentGateway android SDK < Error inflating class com.shamanland.fonticon.FontIconView >

I am integrating Payfort Payment gateway android sdk in my app, every thing is working fine till Payment on Last screen using sdk.
When Clicking on PAY button on the XML design provided by Payfort Team then I am getting
{
if (isInEditMode()) {
mOldValuesSaver = null;
} else {
setTypeface(FontIconTypefaceHolder.getTypeface());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mOldValuesSaver = new Runnable() {
#Override
public void run() {
saveOldValues();
}
};
} else {
mOldValuesSaver = new Runnable() {
#Override
public void run() {
saveOldValuesJB();
}
};
}
}
}
In above method,the line(setTypeface(FontIconTypefaceHolder.getTypeface());) is throwing the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.payfort.payfort/com.example.payfort.payfort.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class com.shamanland.fonticon.FontIconView
Any Help would be appreciated.
Please find the Logs below
/com.example.payfort.payfort E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.payfort.payfort, PID: 23352
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.payfort.payfort/com.example.payfort.payfort.MainActivity}:
android.view.InflateException: Binary XML file line #15: Error
inflating class com.shamanland.fonticon.FontIconView at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:135) at
android.app.ActivityThread.main(ActivityThread.java:5254) at
java.lang.reflect.Method.invoke(Native Method) at
java.lang.reflect.Method.invoke(Method.java:372) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused
by: android.view.InflateException: Binary XML file line #15: Error
inflating class com.shamanland.fonticon.FontIconView at
android.view.LayoutInflater.createView(LayoutInflater.java:633) at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at
android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at
android.view.LayoutInflater.inflate(LayoutInflater.java:504) at
android.view.LayoutInflater.inflate(LayoutInflater.java:414) at
android.view.LayoutInflater.inflate(LayoutInflater.java:365) at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at
com.example.payfort.payfort.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:5990) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:135) at
android.app.ActivityThread.main(ActivityThread.java:5254) at
java.lang.reflect.Method.invoke(Native Method) at
java.lang.reflect.Method.invoke(Method.java:372) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused
by: java.lang.reflect.InvocationTargetException at
java.lang.reflect.Constructor.newInstance(Native Method) at
java.lang.reflect.Constructor.newInstance(Constructor.java:288) at
android.view.LayoutInflater.createView(LayoutInflater.java:607) at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at
android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at
android.view.LayoutInflater.inflate(LayoutInflater.java:504) at
android.view.LayoutInflater.inflate(LayoutInflater.java:414) at
android.view.LayoutInflater.inflate(LayoutInflater.java:365) at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at
com.example.payfort.payfort.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:5990) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:135) at
android.app.ActivityThread.main(ActivityThread.java:5254) at
java.lang.reflect.Method.invoke(Native Method) at
java.lang.reflect.Method.invoke(Method.java:372) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused
by: java.lang.IllegalStateException at
com.shamanland.fonticon.FontIconTypefaceHolder.getTypeface(FontIconTypefaceHolder.java:13)
at com.shamanland.fonticon.FontIconView.(FontIconView.java:129)
at java.lang.reflect.Constructor.newInstance(Native Method) at
java.lang.reflect.Constructor.newInstance(Constructor.java:288) at
android.view.LayoutInflater.createView(LayoutInflater.java:607) at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at
android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at
android.view.LayoutInflater.inflate(LayoutInflater.java:504) at
android.view.LayoutInflater.inflate(LayoutInflater.java:414) at
android.view.LayoutInflater.inflate(LayoutInflater.java:365) at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at
com.example.payfort.payfort.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:5990) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:135) at
android.app.ActivityThread.main(ActivityThread.java:5254) at
java.lang.reflect.Method.invoke(Native Method) at
java.lang.reflect.Method.invoke(Method.java:372) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Just add
FontIconTypefaceHolder.init(getAssets(), "icons.ttf");
before setcontentview

android.view.InflateException: Binary XML file line - how to avoid

I have a problem with inflating, I dont know how to resolve it because it is a strange issue. I got a crash in my BaseFragment class in line 60 for samsung and huawei devices(huawei gra_l09). Code looks like below:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int contentView = onFragmentContentView();
if(contentView == 0)
throw new IllegalArgumentException("onFragmentContentView must be not equal 0");
View layout = inflater.inflate(contentView, container, false); //!!line 60
ButterKnife.inject(this, layout);
onCreateFragmentView(layout, container, savedInstanceState);
return layout;
}
I am not sure if the theme is a reason? I have used Theme.AppCompat.Light.
Fatal Exception: android.view.InflateException: Binary XML file line
2: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.vyda.stream.fragments.BaseFragment.onCreateView(BaseFragment.java:60)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.vyda.stream.fragments.BaseFragment.onCreateView(BaseFragment.java:60)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:977) > byte allocation with 3357954 free bytes and 3MB until OOM
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)
at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2480)
at android.content.res.Resources.loadDrawable(Resources.java:2387)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3754)
at android.view.ViewGroup.<init>(ViewGroup.java:498)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:249)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:245)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:241)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.vyda.stream.fragments.BaseFragment.onCreateView(BaseFragment.java:60)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:977)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)
[Edit]: Whole class code: http://pastebin.com/nSCpY35Y
Add this:
android:largeHeap="true"
in your manifest file to avoid OOM error.
You are having an OOM (Out Of Memory error) byte allocation with 3357954 free bytes and 3MB until OOM check the size of your images.

Android Studio crashes when using adapter and background gradient color

When I use background gradient color together with an adapter the application crashes. When I change the background color to a simple one (such as android:background="#color/blueLgt") - no crash, or when I comment the setAdapter() method. What am I doing wrong?
Here is the test application:
MainActivity.java
package ...mylistview;
import (...)
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] myStringArray={"A","B","C"};
ArrayAdapter<String> myAdapter = new
ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
myStringArray);
ListView myList=(ListView)
findViewById(R.id.listView);
myList.setAdapter(myAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Activity_Main.xml
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/gradient_blue"
android:id="#+id/MainActivity"
tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
drawable/gradient_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/blueMed"
android:centerColor="#color/blueLgt"
android:endColor="#color/blueMed"
android:angle="90">
</gradient>
</shape>
CatLog
07-26 22:51:08.050 656-656/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
07-26 22:51:08.130 656-663/? I/art﹕ Debugger is no longer active
07-26 22:51:08.150 656-663/? W/art﹕ Suspending all threads took: 20ms
--------- beginning of crash
07-26 22:51:08.160 656-656/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: il.co.talkie.mylistview, PID: 656
java.lang.RuntimeException: Unable to start activity ComponentInfo{il.co.talkie.mylistview/il.co.talkie.mylistview.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at il.co.talkie.mylistview.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at il.co.talkie.mylistview.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/gradient_blue.xml from drawable resource ID #0x7f02003b
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2479)
at android.content.res.Resources.loadDrawable(Resources.java:2381)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3737)
at android.view.ViewGroup.<init>(ViewGroup.java:497)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at il.co.talkie.mylistview.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
at android.content.res.TypedArray.getColor(TypedArray.java:404)
at android.graphics.drawable.GradientDrawable.updateGradientDrawableGradient(GradientDrawable.java:1323)
at android.graphics.drawable.GradientDrawable.inflateChildElements(GradientDrawable.java:1176)
at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:1019)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1128)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1032)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469)
at android.content.res.Resources.loadDrawable(Resources.java:2381)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3737)
at android.view.ViewGroup.<init>(ViewGroup.java:497)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at il.co.talkie.mylistview.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
07-26 22:51:44.760 656-663/il.co.talkie.mylistview W/art﹕ Suspending all threads took: 10ms
Problem solved:
From logcat I saw that the problem is because of a null object in the setAdapter() method. I added a check for null object after the creation of myAdapter and it was not null. Then I added a check for null object after the line
ListView myList=(ListView) findViewById(R.id.listView);
and myList was null. checking the xml file of the layout revealed that the obect id was listView2 and not listView. changed it and problem solved.
Nothing to do with the adapter or gradient background.
Thanks Karakuri for pointing me to look at the catlog.

Unable to start activity ComponentInfo{Activity}: android.view.InflateException: Binary XML file line Error inflating class fragment

I am getting the following exception, when I try to start a fragment inside a activity. It seems like this is a common problem, I have all the permissions necessary as suggested in the answers. The trace is not very helpful.
Process: com.eazysystems.transdoc, PID: 11129
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxxx/com.xxxx.xxxx.view.ViewRecordActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.eazysystems.transdoc.view.ViewRecordActivity.onCreate(ViewRecordActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:455)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2135)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:838)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:826)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
            at com.eazysystems.transdoc.view.ViewRecordActivity.onCreate(ViewRecordActivity.java:21)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
And also, the exception happens at the setContentView(R.layout.activity_view_record); in this Activity class. I tried to make the application simple as possible but it get the same exception
public class ViewRecordActivity extends AppCompatActivity {
private static String RECORD_ID = "RECORD_ID";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_record);
/*Bundle extras = getIntent().getExtras();
Integer recordId = extras.getInt(RECORD_ID);*/
ViewRecordFragment viewRecordFragment = ViewRecordFragment.newInstance(1);
//viewRecordFragment.setArguments(getIntent().getExtras());
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager
.beginTransaction()
.replace(R.id.view_record_fragment, viewRecordFragment
).commit();
}
public static class ViewRecordFragment extends Fragment {
private static String RECORD_ID = "RECORD_ID";
public ViewRecordFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/*gridview = (GridView) getActivity().findViewById(R.id.image_grid_view);*/
//Integer recordId = getArguments().getInt(RECORD_ID);
//loadImageResourcesAsync(recordId);
return inflater.inflate(R.layout.fragment_view_record, container, false);
}
public static ViewRecordFragment newInstance(Integer recordId) {
ViewRecordFragment fragment = new ViewRecordFragment();
//fragment.loadImageResourcesAsync(recordId);
/*Bundle bundle = new Bundle();
bundle.putInt(RECORD_ID, recordId);
fragment.setArguments(bundle);*/
return fragment;
}
private void loadImageResourcesAsync(Integer recordId) {
new LoadImageResourcesAsync(getActivity()).execute(recordId);
}
}
}
layout for the activity as follows.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/view_record_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!--<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/view_record_fragment"
android:name="com.xxx.xxx.view.ViewRecordActivity$ViewRecordFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragment_view_record" />-->
</LinearLayout>
Any help is greatly appreciated.
Basic way of adding fragments in layout is like below. You have to mention the class name of the fragment.
<fragment android:name="com.example.android.fragments.HeadlinesFragment"
android:id="#+id/headlines_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />

OnClickListener inside the fragment gives Null Pointer Exception

I have a image button to delete that particular row inside a listview in a fragment.When I run the activity from main activity it gives NPE.
Here is the logcat output
03-10 12:29:36.647 2525-2525/com.restaurantmgmt.dcode1.restaurantms E/libprocessgroup﹕ failed to make and chown /acct/uid_10007: Read-only file system
03-10 12:29:50.351 2525-2525/com.restaurantmgmt.dcode1.restaurantms E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.restaurantmgmt.dcode1.restaurantms, PID: 2525
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.restaurantmgmt.dcode1.restaurantms/com.restaurantmgmt.dcode1.restaurantms.menu}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.restaurantmgmt.dcode1.restaurantms.menu.onCreate(menu.java:18)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.restaurantmgmt.dcode1.restaurantms.SidePanelFragment.onCreateView(SidePanelFragment.java:45)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1147)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2116)
at android.app.Activity.onCreateView(Activity.java:5282)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.restaurantmgmt.dcode1.restaurantms.menu.onCreate(menu.java:18)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Here is the relevant code from the SidePanelActivity
public class SidePanelFragment extends android.app.Fragment implements View.OnClickListener {
ListView list1;
Items addedItems=null;
ImageButton btnDelete;
Items[] addedItms=new Items[100];
//Items[] addedItms=null;
ArrayList<Items> itemsArray=null;
ItemsAdapter1 adapter=null;
int countSideList=0;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragment_side_panel,container,false);
list1=(ListView)view.findViewById(R.id.listViewSide);
btnDelete=(ImageButton)view.findViewById(R.id.btndelete);
itemsArray= new ArrayList<Items>();
btnDelete.setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
Toast.makeText(getActivity(),"btndelete clicked",Toast.LENGTH_LONG);
}
}
And here is the activity which has the fragment
public class menu extends ActionBarActivity implements OnAddItemPressed{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
int screenOrien=getResources().getConfiguration().orientation;
if(screenOrien== Configuration.ORIENTATION_PORTRAIT) {
hideSidePanel();
}
else
{
}
}
private void hideSidePanel() {
View side=findViewById(R.id.side_panel);
if(side.getVisibility()==View.VISIBLE)
{
side.setVisibility(View.GONE);
}
}
#Override
public void onAddItemPressed(Items item){
FragmentManager manager= getFragmentManager();
SidePanelFragment sideObj= (SidePanelFragment) manager.findFragmentById(R.id.side_panel);
sideObj.getAddedItems(item);
}
}
I have set a breakpoint at btnDelete.setOnClickListener(this);
and btnDelete is null in the debug window at that breakpoint.
Try this way :
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btndelete:
Toast.makeText(getActivity(),"btndelete clicked",Toast.LENGTH_LONG);
break;
}
Also try to replace your implements View.OnClickListener to implements OnClickListener
Make sure this btndelete id is on your fragment_side_panel.xml

Categories

Resources