Error inflating class com.facebook.drawee.view.SimpleDraweeView - android

I'm trying to use the fresco library. I used it before too and it was working, but now, for some reason I get:
Unable to start activity ComponentInfo{com.example.home.template/com.example.home.template.MainActivity}: android.view.InflateException: Binary XML file line #26: Error inflating class com.facebook.drawee.view.SimpleDraweeView
My xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/profileImage"
fresco:actualImageScaleType="centerCrop"
android:layout_width="200dp"
android:layout_gravity="center_horizontal"
android:layout_height="200dp" />
</LinearLayout>
MyApplication:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(this);
}
}
I have it in my manifest: android:name=".MyApplication"
The only problem that I'm having is with the draweeview. I can do all of the other stuff such as logging in and taking information.

In my case writing Fresco.initialize(this); before setContentView(R.layout.myxml); helped me.
Update:
you have FacebookSdk.sdkInitialize(this); instead of Fresco.initialize(this) in your myapplication

I was getting this problem in API 19 devices just because I was using drawable vector as placeholder here
fresco:placeholderImage="#drawable/ic_phone"
After changing to PNG my problem was solved.
Dont forget to initialize it in your App as
class App : Application() {
override fun onCreate() {
super.onCreate()
Fresco.initialize(this)
}
}
as well as this line in manifest's application
android:name=".App"

Today I had the same problem. However, I forgot to add the property android:name=".MyApplication" in the AndroidManifest.xml.

In your Application class write the following line:
Fresco.initialize(this);

Make sure that you import the right Fresco library and if you do import other Fresco libraries, make sure the other libraries version number is the same with Fresco core library

Related

Error inflating class com.paypal.checkout.paymentbutton.PaymentButtonContainer

Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.payment.PaymentPayPal">
<com.paypal.checkout.paymentbutton.PaymentButtonContainer
android:id="#+id/paymentButtonContainer"
android:layout_width="match_parent"
android:layout_height="#dimen/_50dp"
android:layout_margin="#dimen/_30dp"
app:layout_constraintTop_toTopOf="parent"/>
</LinearLayout>
My activity class:
class PaymentPayPal : BaseActivity() {
private val YOUR_CLIENT_ID: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_payment_pay_pal)
}
}
also tried binding nothing happens
build.gradle(app)
minSdk=21
dependencies {
implementation 'com.paypal.checkout:android-sdk:0.8.1'
}
Error message:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voterswik/com.voterswik.ui.payment.PaymentPayPal}: android.view.InflateException: Binary XML file line #9 in com.voterswik:layout/activity_payment_pay_pal: Binary XML file line #9 in com.voterswik:layout/activity_payment_pay_pal: Error inflating class com.paypal.checkout.paymentbutton.PaymentButtonContainer
First, this error is due to non-reachable class PaymentButtonContainer
This is because it should build a config before its use, so go to paypal docs
https://developer.paypal.com/limited-release/paypal-mobile-checkout/android/
and check whether implemented correctly, is you "implement configuration on a subclass of Application()" which will call at very start of project. To set the configuration
You cannot use constraints in a LinearLayout.
app:layout_constraintTop_toTopOf="parent"
If you remove that line you will be able to run your app.
You may try these steps.
make sure you have the latest implementation
e.g. implementation'com.paypal.checkout:android-sdk:0.8.8'
make your PayPalCheckout.setConfig in the MainActivity
Create a new Activity and put the PaymentButtonContainer on the new activity.xml

AppCompat v7 not being referenced properly

I'm new to Xamarin Android. I've installed the AppCompatv7 Support Library from the GetComponents option.
But whenever I try and do anything with it, I get no intellisense, like it isn't actually added to the project. Like below:
When I look more into the assembly it comes up with an option like below, saying it might not be installed. But as you can see from the picture, it is installed under my references.
If I click Add Package in the below picture, nothing happens.
When I compile the code, it can't find functions in the ActionBarActivity base class, so I'm guessing it's not adding it properly into my project.
Anyone know why this is happening? Cheers
When I compile the code, it can't find functions in the ActionBarActivity base class, so I'm guessing it's not adding it properly into my project.
ActionBarActivity is obsolete.
To use Android.Support.V7.Widget.Toolbar, after installing the Xamarin.Android.Support.v7.AppCompat package, you can simply inherit your MainActivity from AppCompatActivity instead of ActionBarActivity.
Then for example my toolbar is like this:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toolbartitile"
android:text="Kodej" />
</android.support.v7.widget.Toolbar>
Include this toolbar in Main layout like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="#+id/toolbar"
layout="#layout/mytoolbar" />
</LinearLayout>
And finally in your MainActivity:
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
}
You just need to reference Android.Support.V7.App in your code:
using Android.Support.V7.App;
All references in my demo:
If you've installed the libs correctly and there is no no intellisense, you can try to rebuild your app, close and reopen your VS.
Install it using the NuGet Command Console :
Install-Package Xamarin.Android.Support.v7.AppCompat -Pre

Can't get PreferenceFragmentCompat to work

I am trying to create an Activity that extends AppCompatActivity and has two fragments inside of it (one below another - just by using a LinearLayout). I would like the first fragment to extend the PreferenceFragmentCompat class from the support-v7 library.
I followed Google's short example regarding PreferenceFragmentCompat as shown at https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat.html.
Here is my current code:
GroupDetailsActivity.java
public class GroupDetailsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group_details);
GroupDetailsPrefFragment prefFragment = GroupDetailsPrefFragment.newInstance();
GroupDetailsMembersFragment membersFragment = GroupDetailsMembersFragment.newInstance();
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction()
.add(R.id.flPrefFragment, prefFragment, GroupDetailsPrefFragment.TAG)
.add(R.id.flMembersFragment, membersFragment, GroupDetailsMembersFragment.TAG)
.commit();
}
}
GroupDetailsPrefFragment .java - The problematic fragment
public class GroupDetailsPrefFragment extends PreferenceFragmentCompat {
public static final String TAG = "GroupDetailsPrefFragment";
#Override
public void onCreatePreferences(Bundle bundle, String s) {
setPreferencesFromResource(R.xml.group_details_preferences, s);
}
public static GroupDetailsPrefFragment newInstance() {
GroupDetailsPrefFragment fragment = new GroupDetailsPrefFragment();
return fragment;
}
}
GroupDetailsMembersFragment.java - Completely empty for now..
public class GroupDetailsMembersFragment extends Fragment {
public static final String TAG = "GroupDetailsMembersFragment";
public static GroupDetailsMembersFragment newInstance() {
GroupDetailsMembersFragment fragment = new GroupDetailsMembersFragment();
return fragment;
}
}
activity_group_details.xml - Activity's layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/flPrefFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/flMembersFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
group_details_preferences.xml - The preference XML file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="#string/remove_me"
android:key="#string/pref_key_settings_remove_me"/>
<Preference
android:title="#string/delete_group"
android:key="#string/pref_key_settings_delete_group"/>
</PreferenceScreen>
Trying to compile and run the code above lead me into a few errors, the first one was regarding a preference theme that was not set. I have quickly scanned the internet and found you need to add the following line into your Activity's theme : <item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
To do so, I was needed to add the support-v14 library to gradle!
Trying to run the code again, lead me to another error, which is the reason I am posting this, and so far I didn't find any way to solve this issue. Here is the crash log :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cochat.android/com.cochat.android.ui.groups.details.GroupDetailsActivity}: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list_container' that is not a ViewGroup class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list_container' that is not a ViewGroup class
at android.support.v7.preference.PreferenceFragmentCompat.onCreateView(PreferenceFragmentCompat.java:269)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:181)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1189)
at android.app.Activity.performStart(Activity.java:5441)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) 
at android.app.ActivityThread.access$900(ActivityThread.java:161) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:157) 
at android.app.ActivityThread.main(ActivityThread.java:5356) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
at dalvik.system.NativeStart.main(Native Method) 
Been stuck on this for a while now, tried looking up different posts on stackoverflow or other websites, seen some solutions, but for some reason none of them managed to solve my problem.
Edit:
My gradle file contains the following:
compileSdkVersion 25
buildToolsVersion '25.0.2'
...
compile 'com.android.support:preference-v7:25.1.0'
compile 'com.android.support:preference-v14:25.1.0'
Update Jan 02 '17
I've been looking into the source code of PreferenceFragmentCompat and seen it is trying to load the following layout: R.layout.preference_list_fragment.
In the onCreateView() method of the class, it is inflating the layout, and trying to look for the id android.R.id.list_container.
The problem is that there is no such id within the layout.
Here is a code snippet from the PreferenceFragmentCompat:
final View view = themedInflater.inflate(mLayoutResId, container, false);
final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
if (!(rawListContainer instanceof ViewGroup)) {
throw new RuntimeException("Content has view with id attribute "
+ "'android.R.id.list_container' that is not a ViewGroup class");
}
While
private int mLayoutResId = R.layout.preference_list_fragment;
Still looking for a solution, thanks!
I got past this using the following bugfix:
https://github.com/Gericop/Android-Support-Preference-V7-Fix
Simple 3 step process is to update the app's build.gradle,
Remove:
compile 'com.android.support:preference-v7:25.0.1'
compile 'com.android.support:preference-v14:25.0.1'
Add
compile 'com.takisoft.fix:preference-v7:25.0.1.0'
Then update your app's theme for preferences to use PreferenceFixTheme
(You're already using PreferenceFragmentCompat so good to go).
UPDATE:
On further investigation, with api 25.1.0, AppCompat worked fine once I realized the very strict restrictions on the style for Preferences.
I found this resource very helpful in getting everything set up nicely:
According to this article:
Note that Google changed the needed id from R.id.list_container (in
revision 23.4.0) to android.R.id.list_container (in revision 24.0.0).
Android Studio says the new id requires API 24, but it also works on
older APIs.
ViewGroup in your layout file (activity_group_details.xml) should have id "#android:id/list_container”. to make it work. It can look like this:
<FrameLayout
android:id="#android:id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/flMembersFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
And you have to use this id for your transaction too, note that the other fragment of yours can use any Id for container, only pref is 'special'
So I have found a work around for this, might not be the best, but it is the only thing I have managed to get working! It seems like a problem/bug with the support library..
I have copied the original PreferenceFragmentCompat to a local class, and made minor changed to it. I have replace the following line
private int mLayoutResId = android.support.v7.preference.R.layout.preference_list_fragment;
with
private int mLayoutResId = R.layout.preference_fragment_compat_container;
which is a layout I have made, that it very simple and only contains a container for the list. Here is the layout code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
Doing the above will allow you to use PreferenceFragmentCompat with the specific gradle settings above (see original post) without any problems.
The down side is that upgrading the support libraries will not upgrade your PreferenceFragmentCompat since it is copied of course. You will need to keep track of the support libraries, and when ever the problem is fixed, you may delete the copied class and use the original one.
If you have any other solutions or ideas please share!
I think you just need to use the support PreferenceScreen and Preferences:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.Preference
android:title="#string/remove_me"
android:key="#string/pref_key_settings_remove_me"/>
<android.support.v7.preference.Preference
android:title="#string/delete_group"
android:key="#string/pref_key_settings_delete_group"/>
</android.support.v7.preference.PreferenceScreen>
Checked out my answer here https://stackoverflow.com/a/53560798/1247248
you need a layout resource with that id
Adding this line to your AppTheme in the styles.xml file should do the trick:
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>

Proguard Removing Overridden resource id in android library

I have a library with an LegendActivity using layout legend.xml which references a view with id "icons". Now, in my app, I subclass this activity with "AppLegendActivity" and use the app's overriding legend.xml which does not include any view with id "icons".
Library
public class LegendActivity extends Activity {
#Override
public void onCreate(Bundle b) {
setContentView(R.layout.legend);
View icons_view = findViewById(R.id.icons);
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/icons"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
App
public class AppLegendActivity extends LegendActivity {
#Override
public void onCreate(Bundle b) {
super.onCreate(Bundle b);
View app_icons_view = findViewById(R.id.app_icons);
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/app_icons"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
This is an over-simplification of my actual code, but this is the crux of the problem. When I run pro-guard I get the following error:
Warning: com.example.activity.LegendActivity: can't find referenced field 'int icons' in program class com.example.R$id
If I add the "-dontwarn" flag in proguard, I can get the app to compile, but as soon as the AppLegendActivity calls super.onCreate, the reference to R.id.icons gets called and the app crashes with:
ava.lang.NoSuchFieldError: com.example.r.icons
App's build.grade referencing proguard section:
buildTypes {
release {
// Proguard
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
My proguard-rules.pro
-dontwarn com.example.**
Can this code be re-factored to avoid this crash? Yes. Can I simply rename a few resources files and get this conflict to go away? Sure. But in the actual project, this much more complicated and I don't know the full extend of the implications of such a refactor. Is there a way to get the library's R file to not remove/obfuscate IDs that are no longer visible after the app's overriding of resources?
In AppLegendActivity class you override LegendActivity you need change setContentView(R.layout.....); or remove super.onCreate(Bundle b);

Admob 6.1.0 for monodroid

I have an app made with monodroid, it's on release stage (ready to get released) but I would like to have a free ad-supported version of my app. I've been searching the web for a tutorial of Admob 6.1.0 implementation on monodroid without any luck. I'd have to mention that I've never worked with ads before.
I was wondering if anyone has been able to use Admob 6.1.0 on monodroid and if you could share your knowledge
I've seen this source code and also this tutorial, but I just can't manage to understand correctly how to implement it. I't would be nice if someone could make an answer as a community wiki so it can help others to get introduced to Admob in monodroid
EDIT:
Tried Greg Shackles sample step by step, i'm now getting this error android.view.InflateException: Binary XML file line #1: Error inflating class com.google.ads.AdView. Any sugestion of how to make it work?
EDIT 2:
Changed the XML file and now getting 2 new errors: Java.Lang.NoClassDefFoundError and System.TypeInitializationException. XML looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/Background2"
>
<com.google.ads.AdView android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="AD_UNIT_ID_GOES_HERE"
ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
And adview is called like this:
public class MyActivity : Activity
{
private View _adView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.AboutActivityLayout);
AdMobHelper.RegisterEmulatorAsTestDevice();
_adView = FindViewById(Resource.Id.Ad);
AdMobHelper.RequestFreshAd(_adView);
loadData();
}
}
The first error you got "android.view.InflateException: Binary XML file line #1: Error inflating class com.google.ads.AdView" is related to the Jar Build Action setting.
You should check two things first:
the jar file has the Build Action property set to "AndroidJavaLibrary"
the java file called "AdMobHelper.java" should have the Build Action property set to "AndroidJavaSource"
It seems to me that the error you are getting now is related to the java file not being correctly configured as an AndroidJavaSource.

Categories

Resources