- Home /
Android Snackbar InflateException
Hi all,
I'm currently trying to get a snackbar to show up in my Android app. However, when I try to call the function SnackbarCreate() below, I get an error from LogCat.
Here is the code.
Code (CSharp):
using UnityEngine;
public class Snackbar : MonoBehaviour
{
public void SnackbarCreate()
{
AndroidJavaClass javaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject Context = javaClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass SnackbarClass = new AndroidJavaClass("android.support.design.widget.Snackbar");
AndroidJavaClass id = new AndroidJavaClass("android.R$id");
int content = id.GetStatic<int>("content");
AndroidJavaObject View = Context.Call<AndroidJavaObject>("findViewById", content);
AndroidJavaObject Snackbar = SnackbarClass.CallStatic<AndroidJavaObject>("make", View, "Snackbar test", -1);
Snackbar.Call("show");
}
}
Here is the Logcat message. It was automatically truncated since Logcat has an upper limit on the size of the message. If anyone could help me increase that limit, I would be very grateful.
04-05 15:26:44.754: E/Unity(12251): AndroidJavaException: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class android.widget.TextView
04-05 15:26:44.754: E/Unity(12251): android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class android.widget.TextView
04-05 15:26:44.754: E/Unity(12251): Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class android.widget.TextView
04-05 15:26:44.754: E/Unity(12251): Caused by: java.lang.reflect.InvocationTargetException
04-05 15:26:44.754: E/Unity(12251): at java.lang.reflect.Constructor.newInstance0(Native Method)
04-05 15:26:44.754: E/Unity(12251): at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
04-05 15:26:44.754: E/Unity(12251): at android.view.LayoutInflater.createView(LayoutInflater.java:647)
04-05 15:26:44.754: E/Unity(12251): at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
04-05 15:26:44.754: E/Unity(12251): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
04-05 15:26:44.754: E/Unity(12251): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
04-05 15:26:44.754: E/Unity(12251): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
04-05 15:26:44.754: E/Unity(12251): at android.view.LayoutInflater.rInflate(LayoutInflater.java:8
I am running Unity 2018.3.0f2, Essential Phone Android P. Also tested on an Nvidia Shield tablet (version unknown, I don't have it with me right now), and it produces the same error.
I am not running any Java code or plugins. Just this one C# script.
I would gladly test out any suggestions. Thanks!
Your answer
Follow this Question
Related Questions
Low FPS in Android 1 Answer
Failed to re-package resources even I make blank project 3 Answers
how fix this problem of image ui disappearing when animated. 0 Answers
swipe ui panel 1 Answer
Gradle build faild. see... error "in unity 2020.1.4f1!!!" 0 Answers