Android view inflateexception ошибка

TL/DR: An exception occurred during the creation of a fragment referenced from a higher-level layout XML. This exception caused the higher-level layout inflation to fail, but the initial exception was not reported; only the higher-level inflation failure shows up in the stack trace. To find the root cause, you have to catch and log the initial exception.


The initial cause of the error could be a wide variety of things, which is why there are so many different answers here as to what fixed the problem for each person. For some, it had to do with the id, class, or name attributes. For others it was due to a permissions issue or a build setting. For me, those didn’t fix the problem; instead there was a drawable resource that existed only in drawable-ldrtl-xhdpi, instead of in an applicable place like drawable.

But those are just details. The big-picture problem is that the error message that shows up in logcat doesn’t describe the exception that started it all. When a higher-level layout XML references a fragment, the fragment’s onCreateView() is called. When an exception occurs in a fragment’s onCreateView() (for example while inflating the fragment’s layout XML), it causes the inflation of the higher-level layout XML to fail. This higher-level inflation failure is what gets reported as an exception in the error logs. But the initial exception doesn’t seem to travel up the chain well enough to be reported.

Given that situation, the question is how to expose the initial exception, when it doesn’t show up in the error log.

The solution is pretty straightforward: Put a try/catch block around the contents of the fragment’s onCreateView(), and in the catch clause, log the exception:

public View onCreateView(LayoutInflater inflater, ViewGroup contnr, Bundle savedInstSt) {
    try {
        mContentView = inflater.inflate(R.layout.device_detail_frag, null);
        // ... rest of body of onCreateView() ...
    } catch (Exception e) {
        Log.e(TAG, "onCreateView", e);
        throw e;
    }
}

It may not be obvious which fragment class’s onCreateView() to do this to, in which case, do it to each fragment class that’s used in the layout that caused the problem. For example, in the OP’s case, the app’s code where the exception occurred was

at android.app.Activity.setContentView(Activity.java:1901)

which is

   setContentView(R.layout.activity_main);

So you need to catch exceptions in the onCreateView() of any fragments referenced in layout activity_main.

In my case, the root cause exception turned out to be

Caused by: android.content.res.Resources$NotFoundException: Resource
   "com.example.myapp:drawable/details_view" (7f02006f)  is not a
   Drawable (color or path): TypedValue{t=0x1/d=0x7f02006f a=-1
   r=0x7f02006f}

This exception didn’t show up in the error log until I caught it in onCreateView() and logged it explicitly. Once it was logged, the problem was easy enough to diagnose and fix (details_view.xml existed only under the ldrtl-xhdpi folder, for some reason). The key was catching the exception that was the root of the problem, and exposing it.

It doesn’t hurt to do this as a boilerplate in all your fragments’ onCreateView() methods. If there is an uncaught exception in there, it will crash the activity regardless. The only difference is that if you catch and log the exception in onCreateView(), you won’t be in the dark as to why it happened.

P.S. I just realized this answer is related to @DaveHubbard’s, but uses a different approach for finding the root cause (logging vs. debugger).

Класс из которого идет вызов нового активити

Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
public class RegisterActivity extends AppCompatActivity {
    android.support.v7.widget.AppCompatImageButton btLogin, btSignIn, btImgEn, btImgRu;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
 
        btLogin = (AppCompatImageButton) findViewById(R.id.igBtnLog);
        btSignIn = (AppCompatImageButton) findViewById(R.id.igBtnSignIn);
        btImgEn = (AppCompatImageButton) findViewById(R.id.igBtnLangEn);
        btImgRu = (AppCompatImageButton) findViewById(R.id.igBtnLangRus);
 
 
        btImgRu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               saveLang("Language", "ru");
                if(getLang() !=null)
                    setLocale(getLang());
            }
        });
 
        btImgEn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveLang("Language", "en");
                if(getLang() !=null)
                    setLocale(getLang());
            }
        });
 
        btLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                RegisterActivity.this.startActivity(intent);
            }
        });
 
        btSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegisterActivity.this, NewUserActivity.class);
                RegisterActivity.this.startActivity(intent);
            }
        });
    }
 
    private void saveLang(String key, String value){
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value).commit();
    }
 
 
    private void setLocale(String lang){
        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = getBaseContext().getResources().getConfiguration();
        config.setLocale(locale);
        getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
    }
 
    public String getLang()
    {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        return sharedPreferences.getString("Language",null);
 
    }
 
}
//класс нового активити
 
 
public class LoginActivity extends AppCompatActivity {
 
    final String url = "http://127.0.0.1";
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
 
        ImageButton imageButton = (ImageButton) findViewById(R.id.ieBtnLogOk);
        final TextView etEmail = (TextView)findViewById(R.id.etLogTxt);
        final TextView etPass = (TextView)findViewById(R.id.etRegTxt);
 
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final JSONObject jsonObj= new JSONObject();
                try{
                    jsonObj.put("email", etEmail.getText().toString());
                    jsonObj.put("password", etPass.getText().toString());
                    jsonObj.put("rememberMe", 0);
                }catch (JSONException e){
                    e.printStackTrace();
                }
 
                final JSONObject jsonObject = new JSONObject();
                try{
                    jsonObject.put("LoginForm", jsonObj);
                }catch (JSONException e){
                    e.printStackTrace();
                }
                final String body = jsonObject.toString();
 
 
                RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
 
 
                StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                        new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                System.out.println("RESPONSE_STRING: " + response);
 
                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        System.out.println("error " + error);
                    }
                }) {
                    @Override
                    public String getBodyContentType() {
                        return "application/json; charset=utf-8";
                    }
                    @Override
                    public byte[] getBody() throws AuthFailureError {
                        try {
                            return body == null ? null : body.getBytes("utf-8");
                        } catch (UnsupportedEncodingException uee) {
                            VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", body, "utf-8");
                            return null;
                        }
                    }
 
                };
                queue.add(stringRequest);
 
                Intent intent = new Intent(LoginActivity.this, CalculateActivity.class);
                startActivity(intent);
            }
        });
    }

Register layout

<?xml version=»1.0″ encoding=»utf-8″?>
<android.support.constraint.ConstraintLayout 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=»com.kaytus.customdev.RegisterActivity»>

<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnLangRus»
android:layout_width=»143dp»
android:layout_height=»129dp»
android:layout_marginEnd=»116dp»
android:layout_marginStart=»116dp»
android:layout_marginTop=»16dp»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toTopOf=»parent»
app:srcCompat=»@mipmap/ic_rus» />

<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnLangEn»
android:layout_width=»157dp»
android:layout_height=»141dp»
android:layout_marginBottom=»180dp»
android:layout_marginEnd=»111dp»
android:layout_marginStart=»111dp»
android:background=»@color/colorWhite»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintHorizontal_bias=»0.545″
app:layout_constraintStart_toStartOf=»parent»
app:srcCompat=»@mipmap/ic_eng» />

<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnSignIn»
android:layout_width=»115dp»
android:layout_height=»104dp»
android:layout_marginBottom=»35dp»

android:layout_marginStart=»32dp»
android:layout_marginTop=»373dp»
android:background=»@color/colorWhite»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintStart_toEndOf=»@+id/igBtnLog»
app:layout_constraintTop_toTopOf=»parent»
app:layout_constraintVertical_bias=»0.755″
app:srcCompat=»@mipmap/ic_register» />

<android.support.v7.widget.AppCompatImageButton
android:id=»@+id/igBtnLog»
android:layout_width=»92dp»
android:layout_height=»98dp»
android:layout_marginBottom=»35dp»
android:layout_marginEnd=»32dp»
android:layout_marginTop=»378dp»
android:background=»@color/colorWhite»
android:scaleType=»fitStart»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toStartOf=»@+id/igBtnSignIn»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toTopOf=»parent»
app:layout_constraintVertical_bias=»0.755″
app:srcCompat=»@mipmap/ic_login» />
</android.support.constraint.ConstraintLayout>

Login layout

<?xml version=»1.0″ encoding=»utf-8″?>
<android.support.constraint.ConstraintLayout 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=»com.kaytus.customdev.LoginActivity»>

<EditText
android:id=»@+id/etLogTxt»
android:layout_width=»213dp»
android:layout_height=»38dp»
android:layout_marginEnd=»100dp»
android:layout_marginTop=»52dp»
android:ems=»10″
android:hint=»@string/etHintLog»
android:inputType=»textPersonName»
android:textSize=»14sp»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintTop_toBottomOf=»@+id/imageView3″ />

<EditText
android:id=»@+id/etRegTxt»
android:layout_width=»211dp»
android:layout_height=»wrap_content»
android:layout_marginEnd=»100dp»
android:layout_marginTop=»24dp»
android:ems=»10″
android:hint=»@string/etHintReg»
android:inputType=»textPersonName»
android:textSize=»14sp»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintTop_toBottomOf=»@+id/etLogTxt» />

<ImageView
android:id=»@+id/imageView3″
android:layout_width=»127dp»
android:layout_height=»103dp»
android:layout_marginStart=»16dp»
android:layout_marginTop=»24dp»
android:contentDescription=»@android:string/untitled»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toTopOf=»parent»
app:srcCompat=»@mipmap/ic_login» />

<ImageButton
android:id=»@+id/ieBtnLogOk»
android:layout_width=»wrap_content»
android:layout_height=»wrap_content»
android:layout_marginBottom=»69dp»
android:layout_marginTop=»47dp»
android:background=»@drawable/ic_launcher_foreground»
android:contentDescription=»@android:string/ok»
app:layout_constraintBottom_toBottomOf=»parent»
app:layout_constraintEnd_toEndOf=»parent»
app:layout_constraintStart_toStartOf=»parent»
app:layout_constraintTop_toBottomOf=»@+id/etRegTxt»
app:srcCompat=»@mipmap/ic_buttonok» />

</android.support.constraint.ConstraintLayout>

The android.view.InflateException Error inflating class android.webkit.WebView is a common error that occurs when attempting to inflate a WebView in an Android application. This error is usually caused by a problem with the layout definition or the class definition of the WebView. The following are several methods to resolve this issue:

Method 1: Use the appropriate context when inflating the WebView

To fix the android.view.InflateException Error inflating class android.webkit.WebView, you need to use the appropriate context when inflating the WebView. Here are the steps to do it:

  1. In your layout XML file, define the WebView with the android.webkit.WebView class.
<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. In your activity or fragment, get the WebView reference and inflate it using the appropriate context.
WebView webView = findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.example.com");

// Use the appropriate context when inflating the WebView
Context context = webView.getContext().getApplicationContext();
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.activity_main, null);
  1. Make sure to use the getApplicationContext() method to get the context instead of the activity context.
// Use the appropriate context when inflating the WebView
Context context = webView.getContext().getApplicationContext();
  1. Finally, set the inflated view as the content view of your activity or fragment.

That’s it! By using the appropriate context when inflating the WebView, you should be able to fix the android.view.InflateException Error inflating class android.webkit.WebView issue.

Method 2: Make sure the WebView class is imported correctly

To fix the android.view.InflateException Error inflating class android.webkit.WebView, you need to make sure the WebView class is imported correctly. Here are the steps to do it:

  1. Import the WebView class in your Java file:
import android.webkit.WebView;
  1. Declare a WebView variable in your Java file:
  1. In your XML layout file, add the WebView element:
<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. In your Java file, initialize the WebView variable in the onCreate() method:
webView = findViewById(R.id.webview);
  1. Load a URL in the WebView:
webView.loadUrl("https://www.example.com");

That’s it! Your WebView should now work without any errors.

Note: Make sure you have added the internet permission in your AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />

Method 3: Use the AppCompatWebView instead of WebView

To fix the android.view.InflateException error when inflating the android.webkit.WebView, you can use the AppCompatWebView instead of the WebView. Here are the steps to do it:

  1. Add the following dependency to your app’s build.gradle file:
implementation 'androidx.webkit:webkit:1.4.0'
  1. Replace the WebView in your layout XML file with androidx.webkit.widget.AppCompatWebView.
<androidx.webkit.widget.AppCompatWebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. In your activity or fragment, use AppCompatWebView instead of WebView.
import androidx.webkit.WebViewClientCompat;
import androidx.webkit.WebViewCompat;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebResourceErrorCompat;
import androidx.webkit.WebResourceRequestCompat;
import androidx.webkit.WebResourceResponseCompat;
import androidx.webkit.WebViewAssetLoader;

import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;

public class MyActivity extends AppCompatActivity {

    private AppCompatWebView mWebView;
    private ProgressBar mProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = findViewById(R.id.web_view);
        mProgressBar = findViewById(R.id.progress_bar);

        // Enable JavaScript
        WebSettingsCompat.setJavaScriptEnabled(mWebView.getSettings(), true);

        // Set WebViewClient
        mWebView.setWebViewClient(new WebViewClientCompat() {
            @Override
            public void onPageStarted(AppCompatWebView view, String url, Bitmap favicon) {
                mProgressBar.setVisibility(View.VISIBLE);
            }

            @Override
            public void onPageFinished(AppCompatWebView view, String url) {
                mProgressBar.setVisibility(View.GONE);
            }

            @Override
            public void onReceivedError(AppCompatWebView view, WebResourceRequestCompat request, WebResourceErrorCompat error) {
                Toast.makeText(MyActivity.this, "Error: " + error.getDescription(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onReceivedHttpError(AppCompatWebView view, WebResourceRequestCompat request, WebResourceResponseCompat errorResponse) {
                Toast.makeText(MyActivity.this, "HTTP error: " + errorResponse.getStatusCode(), Toast.LENGTH_SHORT).show();
            }
        });

        // Load URL
        mWebView.loadUrl("https://www.example.com");
    }

    @Override
    protected void onDestroy() {
        mWebView.destroy();
        super.onDestroy();
    }
}

That’s it! Now you should be able to use AppCompatWebView without getting the android.view.InflateException error.

Method 4: Check for any XML syntax errors in the layout definition

To fix the android.view.InflateException Error inflating class android.webkit.WebView error, you can start by checking for any XML syntax errors in the layout definition. Here’s how:

  1. Open the layout file where the android.webkit.WebView is being used.
  2. Look for any syntax errors in the XML code, such as missing closing tags or incorrect attribute values.
  3. Correct any errors that you find. Here’s an example of a corrected WebView element:
<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:scrollbars="none"
    android:background="@android:color/white"/>
  1. Save the layout file and try running your app again.

By checking for and correcting any XML syntax errors in your layout file, you can resolve the android.view.InflateException Error inflating class android.webkit.WebView error and ensure that your WebView element is properly inflated.

Method 5: Make sure the WebView is not being instantiated before the Activity is created

To fix the android.view.InflateException Error inflating class android.webkit.WebView, make sure the WebView is not being instantiated before the Activity is created. Here are the steps to do it:

  1. Remove the WebView from the XML layout file.
  2. Create a new instance of WebView in the onCreate method of your Activity.
  3. Add the new instance of WebView to the layout programmatically.

Here is the code snippet:

public class MainActivity extends AppCompatActivity {
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create a new instance of WebView
        webView = new WebView(this);

        // Add the new instance of WebView to the layout programmatically
        LinearLayout layout = findViewById(R.id.webview_layout);
        layout.addView(webView);

        // Load the URL
        webView.loadUrl("https://www.example.com");
    }
}

In this example, we create a new instance of WebView in the onCreate method of the Activity and add it to the layout programmatically. We then load the URL using the loadUrl method.

Make sure to replace R.layout.activity_main with your layout file and https://www.example.com with your desired URL.

This should fix the android.view.InflateException Error inflating class android.webkit.WebView issue.

On Android 5.0/ 5.1, it can’t resolve the WebView layout as it thrown Resources NotFoundException
And I’m been searched over stackoverflow and Google Bug Tracker and seems it’s known bug cause by AndroidX AppCompat 1.1.0:
Link 1
Link 2
Link 3

And based on the community reporting, this following bug is fixed on AndroidX AppCompat 1.2.0 already.
It’s there any timeline for the C# binding of the library available? Since my current supporting apps need to compatible with Android 5.0 and 5.1 as well and we are now currently progressing for Android SDK 29 update as well as Support Library to AndroidX Lib migration.

And based on the community seems revert to AppCompat 1.0.2 seems doesn’t have any issue but currently Xamarin.AndroidX.Migration doesn’t allow me to do that as Google.Material Library need AppCompat 1.1.0

Android.Views.InflateException: Binary XML file line #8: Error inflating class android.webkit.WebView ---> Java.Lang.Reflect.InvocationTargetException:  ---> Android.Content.Res.Resources+NotFoundException: String resource ID #0x2040003
  at android.content.res.Resources$NotFoundException: String resource ID #0x2040003
  at at android.content.res.Resources.getText(Resources.java:299)
  at at android.content.res.Resources.getString(Resources.java:385)
  at at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
  at at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
  at at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
  at at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
  at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
  at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
  at at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
  at at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
  at at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
  at at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
  at at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
  at at android.webkit.WebView.<init>(WebView.java:554)
  at at android.webkit.WebView.<init>(WebView.java:489)
  at at android.webkit.WebView.<init>(WebView.java:472)
  at at android.webkit.WebView.<init>(WebView.java:459)
  at at java.lang.reflect.Constructor.newInstance(Native Method)
  at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
  at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
  at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
  at at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
  at at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
  at at crc64bba675e3487af45b.WebViewActivity.n_onCreate(Native Method)
  at at crc64bba675e3487af45b.WebViewActivity.onCreate(WebViewActivity.java:38)
  at at android.app.Activity.performCreate(Activity.java:5990)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
  at at android.app.ActivityThread.access$800(ActivityThread.java:151)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:135)
  at at android.app.ActivityThread.main(ActivityThread.java:5254)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:372)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  --- End of inner exception stack trace ---
  at java.lang.reflect.InvocationTargetException
  at at java.lang.reflect.Constructor.newInstance(Native Method)
  at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
  at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
  at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
  at at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
  at at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
  at at crc64bba675e3487af45b.WebViewActivity.n_onCreate(Native Method)
  at at crc64bba675e3487af45b.WebViewActivity.onCreate(WebViewActivity.java:38)
  at at android.app.Activity.performCreate(Activity.java:5990)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
  at at android.app.ActivityThread.access$800(ActivityThread.java:151)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:135)
  at at android.app.ActivityThread.main(ActivityThread.java:5254)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:372)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  at Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
  at at android.content.res.Resources.getText(Resources.java:299)
  at at android.content.res.Resources.getString(Resources.java:385)
  at at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
  at at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
  at at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
  at at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
  at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
  at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
  at at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
  at at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
  at at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
  at at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
  at at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
  at at android.webkit.WebView.<init>(WebView.java:554)
  at at android.webkit.WebView.<init>(WebView.java:489)
  at at android.webkit.WebView.<init>(WebView.java:472)
  at at android.webkit.WebView.<init>(WebView.java:459)
  at ... 28 more
  --- End of inner exception stack trace ---
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0
  at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <55654ebe9f2a48e6bade2862bb243f94>:0
  at BaseAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00009] in BaseAppCompatActivity.cs:38
  at BaseToolbarAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00001] in BaseToolbarAppCompatActivity.cs:30
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <55654ebe9f2a48e6bade2862bb243f94>:0
  at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
  at android.view.InflateException: Binary XML file line #8: Error inflating class android.webkit.WebView
  at at android.view.LayoutInflater.createView(LayoutInflater.java:633)
  at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
  at at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
  at at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
  at at crc64bba675e3487af45b.WebViewActivity.n_onCreate(Native Method)
  at at crc64bba675e3487af45b.WebViewActivity.onCreate(WebViewActivity.java:38)
  at at android.app.Activity.performCreate(Activity.java:5990)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
  at at android.app.ActivityThread.access$800(ActivityThread.java:151)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:135)
  at at android.app.ActivityThread.main(ActivityThread.java:5254)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:372)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  at Caused by: java.lang.reflect.InvocationTargetException
  at at java.lang.reflect.Constructor.newInstance(Native Method)
  at at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
  at at android.view.LayoutInflater.createView(LayoutInflater.java:607)
  at ... 25 more
  at Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040003
  at at android.content.res.Resources.getText(Resources.java:299)
  at at android.content.res.Resources.getString(Resources.java:385)
  at at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:684)
  at at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
  at at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:631)
  at at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:780)
  at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:619)
  at at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:556)
  at at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:311)
  at at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:96)
  at at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:263)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:123)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:110)
  at at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
  at at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:107)
  at at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:260)
  at at android.webkit.WebView.<init>(WebView.java:554)
  at at android.webkit.WebView.<init>(WebView.java:489)
  at at android.webkit.WebView.<init>(WebView.java:472)
  at at android.webkit.WebView.<init>(WebView.java:459)
  at ... 28 more
  • Remove From My Forums
  • Question

  • User1763 posted

    Hi,

    My code is

    Main.axml:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/MyButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/Hello" />
        <fragement
            android:name="test.fragement.example.Fragment1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout> 
    

    and Activity1.cs

    public class Activity1 : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);          
        }
    }
    

    and Fragment1.cs

    namespace test.fragement.example
    {
        public class Fragment1 : Fragment
        {
            public override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
            }
            public override View OnCreateView(LayoutInflater inflater, ViewGroup grp, Bundle bundle)
            {
                base.OnCreateView(inflater, grp, bundle);
                View vw = inflater.Inflate(Resource.Layout.frag1, grp, true);
                return vw;
            }
        }
    }
    

    This code is throwing an error for me. Stack trace

    Android.Views.InflateException: Binary XML file line #1: Error inflating class fragement
      at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00024] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.4-series/6418373f/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:616
      at Android.App.Activity.SetContentView (int) [0x0006b] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.4-series/6418373f/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:3119
      at test.fragement.example.Activity1.OnCreate (Android.OS.Bundle) [0x00009] in c:Monotest.fragement.exampletest.fragement.exampleActivity1.cs:22
      at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.4-series/6418373f/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:1490
      at (wrapper dynamic-method) object.4b6fec41-0b84-4cbb-85e3-f821d04add6e (intptr,intptr,intptr) <IL 0x00017, 0x00043>
      --- End of managed exception stack trace ---
      android.view.InflateException: Binary XML file line #1: Error inflating class fragement
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
        at android.app.Activity.setContentView(Activity.java:1657)
        at test.fragement.example.Activity1.n_onCreate(Native Method)
        at test.fragement.example.Activity1.onCreate(Activity1.java:28)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:3683)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)
      Caused by: java.lang.ClassNotFoundException: android.view.fragement in loader dalvik.system.PathClassLoader[/data/app/test.fragement.example-1.apk]
        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at android.view.LayoutInflater.createView(LayoutInflater.java:471)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
        ... 21 more
    

    How to solve this ?

Answers

  • User7668 posted

    What a numpty. I have put the namespace in the path for the classname now and of course it works. Sorry for wasting everyone’s time

    • Marked as answer by

      Thursday, June 3, 2021 12:00 AM

Возможно, вам также будет интересно:

  • Android studio ошибка при запуске эмулятора
  • Android studio ошибка при запуске приложения 0xc000007b
  • Android studio ошибка your sdk location contains non ascii characters
  • Android studio ошибка your project location contains non ascii characters
  • Android studio ошибка design editor is unavailable until after a successful project sync

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии