pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

升級我的 Fragment 的導航版本時出現問題(從 2.3.

Problem upgrading my Fragment#39;s Navigation version(from 2.3.5 to 2.4.0-alpha03)(升級我的 Fragment 的導航版本時出現問題(從 2.3.5 到 2.4.0-alpha03))
本文介紹了升級我的 Fragment 的導航版本時出現問題(從 2.3.5 到 2.4.0-alpha03)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我一直在嘗試將片段的導航版本從 2.3.5 升級到 2.4.0-alpha03,以便它可以根據文檔支持多個回棧https://developer.android.com/jetpack/androidx/releases/navigation

I have been trying to upgrade my fragment's navigation version from 2.3.5 to 2.4.0-alpha03 so that it can support multiple back stacks as per the documentation https://developer.android.com/jetpack/androidx/releases/navigation

并且還幫助保存和恢復我的每個底部導航項目的狀態幾天現在不成功.每次我在 build.gradle 中同步實現時,我的 homeactivity 中的代碼都會拋出此錯誤 cannot resolve symbol

and also help in saving and restoring the state of each of my bottom nav items for a few days now unsuccessfully. Each time I sync the implementations in my build.gradle, code in my homeactivity throws this error cannot resolve symbol

final NavController navController = navHostFragment.getNavController(); 
NavigationUI.setupWithNavController(bottomNavigationView, navController);
FirstFragment firstFragment = (FirstFragment) navHostFragment.getChildFragmentManager().getFragments().get(0);

以及他們的進口

import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;

也拋出錯誤未使用導入語句,無法解析符號.因此,如果我運行該應用程序,它就無法執行我希望它執行的上述功能.

throw an error too unused import statement, cannot resolve symbol. So if I run the app, it's unable to perform the above functions that I want it to.

這是我迄今為止嘗試過的:

Here's what i've tried so far:

  • 我添加了這個實現androidx.navigation:navigation-fragment:2.4.0-alpha03"并實現androidx.navigation:navigation-ui:2.4.0-alpha03"到我的build.gradle(app).
  • I've added this implementation "androidx.navigation:navigation-fragment:2.4.0-alpha03" and implementation "androidx.navigation:navigation-ui:2.4.0-alpha03" to my build.gradle(app).

但它并沒有解決.

編輯

我的 Android Gradle 插件版本是 4.0.2

My Android Gradle Plugin version is 4.0.2

我的 Gradle 版本是 6.1.1

My Gradle Version is 6.1.1

我相信有些事情我沒有做對,或者我應該做的事情我沒有做.如果有人能指出這一點,我將不勝感激.

I believe there's something I didn't do right or something I'm meant to do that I didn't do. Please I'd appreciate it if anyone can identify that.

這是我的具體代碼:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.viz.lightweatherforecast"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation "androidx.navigation:navigation-fragment:2.4.0-alpha03"
    implementation "androidx.navigation:navigation-ui:2.4.0-alpha03"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.media2:media2:1.0.0-alpha04'
    implementation 'org.jetbrains:annotations:15.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

Build.gradle(項目):

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

HomeActivity.java:

package com.viz.lightweatherforecast.Activity;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.viz.lightweatherforecast.FirstFragment;
import com.viz.lightweatherforecast.R;
import com.viz.lightweatherforecast.Retrofit.ApiClient;
import com.viz.lightweatherforecast.Retrofit.ApiInterface;
import com.viz.lightweatherforecast.Retrofit.Example;

import org.jetbrains.annotations.NotNull;

import java.util.Timer;
import java.util.TimerTask;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class HomeActivity extends AppCompatActivity {
    // Last update time, click sound, search button, search panel.
    TextView time_field;
    MediaPlayer player;
    ImageView Search;
    EditText textfield;
    // For scheduling background image change(using constraint layout, start counting from dubai, down to statue of liberty.
    ConstraintLayout constraintLayout;
    public static int count=0;
    int[] drawable =new int[]{R.drawable.dubai,R.drawable.central_bank_of_nigeria,R.drawable.eiffel_tower,R.drawable.hong_kong,R.drawable.statue_of_liberty};
    Timer _t;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        // use home activity layout.

        time_field = findViewById(R.id.textView9);
        Search = findViewById(R.id.imageView4);
        textfield = findViewById(R.id.textfield);
        //  find the id's of specific variables.

        BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
        // host 3 fragments along with bottom navigation.
        final NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
        assert navHostFragment != null;
        final NavController navController = navHostFragment.getNavController();
        NavigationUI.setupWithNavController(bottomNavigationView, navController);


        // For scheduling background image change
        constraintLayout = findViewById(R.id.layout);
        constraintLayout.setBackgroundResource(R.drawable.dubai);
        _t = new Timer();
        _t.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                // run on ui thread
                runOnUiThread(() -> {
                    if (count < drawable.length) {

                        constraintLayout.setBackgroundResource(drawable[count]);
                        count = (count + 1) % drawable.length;
                    }
                });
            }
        }, 5000, 5000);

        Search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // make click sound when search button is clicked.
                player = MediaPlayer.create(HomeActivity.this, R.raw.click);
                player.start();

                getWeatherData(textfield.getText().toString().trim());
                // make use of some fragment's data
                FirstFragment firstFragment = (FirstFragment) navHostFragment.getChildFragmentManager().getFragments().get(0);
                firstFragment.getWeatherData(textfield.getText().toString().trim());

            }

            private void getWeatherData(String name) {

                ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);

                Call<Example> call = apiInterface.getWeatherData(name);

                call.enqueue(new Callback<Example>() {
                    @Override
                    public void onResponse(@NonNull Call<Example> call, @NonNull Response<Example> response) {

                        try {
                            assert response.body() != null;
                            time_field.setVisibility(View.VISIBLE);
                            time_field.setText("Last Updated:" + " " + response.body().getDt());
                        } catch (Exception e) {
                            time_field.setVisibility(View.GONE);
                            time_field.setText("Last Updated: Unknown");
                            Log.e("TAG", "No City found");
                            Toast.makeText(HomeActivity.this, "No City found", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onFailure(@NotNull Call<Example> call, @NotNull Throwable t) {
                        t.printStackTrace();
                    }

                });
            }

        });
    }
}

Activity_home.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layout"
    android:background="@drawable/dubai"
    tools:context=".Activity.HomeActivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_menu" />

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="409dp"
        android:layout_height="599dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:navGraph="@navigation/my_nav"
        />

    <EditText
        android:id="@+id/textfield"
        android:layout_width="250dp"
        android:layout_height="35dp"
        android:autofillHints="@string/change_city"
        android:background="@color/colorPrimary"
        android:hint="@string/search_city"
        android:inputType="text"
        android:labelFor="@id/imageView4"
        android:padding="8dp"
        android:textColor="@color/colorAccent"
        android:textSize="16sp"
        app:layout_constraintEnd_toStartOf="@+id/imageView4"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="50dp"
        android:layout_height="35dp"
        android:layout_marginEnd="1dp"
        android:contentDescription="@string/searchbtn"
        android:src="@drawable/look"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/time_field"
        android:visibility="gone"
        android:textColor="#FFFFFF"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textfield" />


</androidx.constraintlayout.widget.ConstraintLayout>

推薦答案

我也在做同樣的事情 首先不要使用 2.4.0 alpha-03 因為他們有問題.

I am also working on the same thing first of all don't use 2.4.0 alpha-03 because they have a problem .

從開發者頁面復制粘貼

已知問題

在使用 Gradle 6.7.0 時,由于依賴于舊版本的 Kotlin.這可以通過更新使用 Gradle 7.0 來解決.(b/190739257)

Safe Args will fail with an Unable to find method ‘’java.lang.String kotlin.text.CarsKt.titleCase(char, java.util.Locale)’’ error when using Gradle 6.7.0 due to a dependency on an older version of Kotlin. This can be worked around by updating to use Gradle 7.0. (b/190739257)

所以這將在 2.4.0 alpha04 中修復,然后使用 2.4.0 alpha02

So this will fix in 2.4.0 alpha04 till then use 2.4.0 alpha02

所以這不是實際問題嘗試降級并使用最新日志更新您的問題,以便我可以幫助您

So this is not the actual problem try to downgrade and update your question with the latest logs so I can help you that

這篇關于升級我的 Fragment 的導航版本時出現問題(從 2.3.5 到 2.4.0-alpha03)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 紫外可见光分光度计-紫外分光度计-分光光度仪-屹谱仪器制造(上海)有限公司 | 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 气弹簧定制-气动杆-可控气弹簧-不锈钢阻尼器-工业气弹簧-可调节气弹簧厂家-常州巨腾气弹簧供应商 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 智能垃圾箱|垃圾房|垃圾分类亭|垃圾分类箱专业生产厂家定做-宿迁市传宇环保设备有限公司 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | PC阳光板-PC耐力板-阳光板雨棚-耐力板雨棚,厂家定制[优尼科板材] | 不锈钢水箱生产厂家_消防水箱生产厂家-河南联固供水设备有限公司 | 酒店品牌设计-酒店vi设计-酒店标识设计【国际级】VI策划公司 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 雷达液位计_超声波风速风向仪_雨量传感器_辐射传感器-山东风途物联网 | 斗式提升机,斗式提升机厂家-淄博宏建机械有限公司 | 合肥花魁情感婚姻咨询中心_挽回爱情_修复婚姻_恋爱指南 | 仿古瓦,仿古金属瓦,铝瓦,铜瓦,铝合金瓦-西安东申景观艺术工程有限公司 | 氢氧化钙设备, 氢氧化钙生产线-淄博惠琛工贸有限公司 | 南京技嘉环保科技有限公司-杀菌除臭剂|污水|垃圾|厕所|橡胶厂|化工厂|铸造厂除臭剂 | 至顶网| 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 上海质量认证办理中心| 电磁辐射仪-电磁辐射检测仪-pm2.5检测仪-多功能射线检测仪-上海何亦仪器仪表有限公司 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 小型气象站_便携式自动气象站_校园气象站-竞道气象设备网 | 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 塑料托盘厂家直销-吹塑托盘生产厂家-力库塑业【官网】 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 防水接头-电缆防水接头-金属-电缆密封接头-不锈钢电缆接头 | SEO网站优化,关键词排名优化,苏州网站推广-江苏森歌网络 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 盐城网络公司_盐城网站优化_盐城网站建设_盐城市启晨网络科技有限公司 | 丝杆升降机-不锈钢丝杆升降机-非标定制丝杆升降机厂家-山东鑫光减速机有限公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 交通信号灯生产厂家_红绿灯厂家_电子警察监控杆_标志杆厂家-沃霖电子科技 | 塑料脸盆批发,塑料盆生产厂家,临沂塑料广告盆,临沂家用塑料盆-临沂市永顺塑业 | 耐酸泵,耐酸泵厂家-淄博华舜耐腐蚀真空泵 | 艺术涂料_进口艺术涂料_艺术涂料加盟_艺术涂料十大品牌 -英国蒙太奇艺术涂料 | COD分析仪|氨氮分析仪|总磷分析仪|总氮分析仪-圣湖Greatlake | 防潮防水通风密闭门源头实力厂家 - 北京酷思帝克门窗 | 新疆十佳旅行社_新疆旅游报价_新疆自驾跟团游-新疆中西部国际旅行社 | 箱式破碎机_移动方箱式破碎机/价格/厂家_【华盛铭重工】 | 南京兰江泵业有限公司-水解酸化池潜水搅拌机-絮凝反应池搅拌机-好氧区潜水推进器 |