亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

android.view.InflateException:二進制 XML 文件第 2 行:

android.view.InflateException:二進制 XML 文件第 2 行:

陪伴而非守候 2023-05-10 15:11:21
我正在嘗試自己學習 android 開發,因為我試圖使用按鈕和文本視圖制作一個簡單的文本更改應用程序,但是當我使用 USB 在我自己的手機上運行它時,它開始顯示,不幸的是,該應用程序已停止。如果你不介意幫助我了解這個錯誤即將到來以及如何解決它。MainActivity.java package com.nanb.wishes;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class MainActivity extends AppCompatActivity  {TextView txt1, txt2;Button btn;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    final TextView txt1 = (TextView) findViewById(R.id.txt1);    final TextView txt2 = (TextView) findViewById(R.id.txt2);    Button btn = (Button) findViewById(R.id.btn);    btn.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View view) {            txt1.setText("Happy birthday to a special person who is bringing so much joy with her smile. I am thankful for every moment we spend together, and I wish your happiness never ends.");            txt2.setText("");        }    });    btn.setOnLongClickListener(new View.OnLongClickListener() {        @Override        public boolean onLongClick(View view) {            txt1.setText(" May this day be as sunny as your smile, and as beautiful as you are. You shine every day, but on this day you will shine the brightest. Happy Birthday");            txt2.setText("");            return true;        }    });    }}activity_main.xml<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.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:id="@+id/layout"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/birthday"tools:context=".MainActivity">
查看完整描述

1 回答

?
holdtom

TA貢獻1805條經驗 獲得超10個贊

這是將 android 項目遷移到 androidX 項目后會出現的一些錯誤。

這是檢查或解決這些錯誤的一些步驟

第 1 步:-確保你在 gradle 文件中的實現。

第 2 步:- Android studio 自動更改所有庫實現,并根據 android X 使用它。如果不知何故未完成,則更改 .xml 文件

例子 :-

     androidx.constraintlayout.ConstraintLayout (wrong).

改成

     androidx.constraintlayout.widget.ConstraintLayout (right).

注意: -你必須添加

     android.enableJetifier=true
     android.useAndroidX=true

gradle.properties 文件中的這兩行。如果該文件不存在,則創建它。在遷移項目時。

現在,這幾乎完成了

如果在那之后也出現錯誤,請構建 > 重建。或者您可以從文件菜單中選擇使緩存無效/重新啟動。

我認為它對所有正在遷移項目的人都有幫助。


查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號