我正在嘗試自己學(xué)習(xí) android 開發(fā),因為我試圖使用按鈕和文本視圖制作一個簡單的文本更改應(yīng)用程序,但是當(dāng)我使用 USB 在我自己的手機(jī)上運(yùn)行它時,它開始顯示,不幸的是,該應(yīng)用程序已停止。如果你不介意幫助我了解這個錯誤即將到來以及如何解決它。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貢獻(xiàn)1805條經(jīng)驗 獲得超10個贊
這是將 android 項目遷移到 androidX 項目后會出現(xiàn)的一些錯誤。
這是檢查或解決這些錯誤的一些步驟
第 1 步:-確保你在 gradle 文件中的實(shí)現(xiàn)。
第 2 步:- Android studio 自動更改所有庫實(shí)現(xiàn),并根據(jù) android X 使用它。如果不知何故未完成,則更改 .xml 文件
例子 :-
androidx.constraintlayout.ConstraintLayout (wrong).
改成
androidx.constraintlayout.widget.ConstraintLayout (right).
注意: -你必須添加
android.enableJetifier=true android.useAndroidX=true
gradle.properties 文件中的這兩行。如果該文件不存在,則創(chuàng)建它。在遷移項目時。
現(xiàn)在,這幾乎完成了
如果在那之后也出現(xiàn)錯誤,請構(gòu)建 > 重建。或者您可以從文件菜單中選擇使緩存無效/重新啟動。
我認(rèn)為它對所有正在遷移項目的人都有幫助。
添加回答
舉報
0/150
提交
取消