> java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/MutableLiveData;

huangapple go评论101阅读模式
英文:

>java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/MutableLiveData;

问题

以下是您要翻译的代码部分:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/MutableLiveData;
	at androidx.fragment.app.Fragment.<init>(Fragment.java:254)
	at com.plz.djaman.allsaver.settingFrag.<init>(settingFrag.java:18)
	at com.plz.djaman.allsaver.homeActivity$100000000.onNavigationItemSelected(homeActivity.java:36)
	at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:204)
	at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
	at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
	at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
	at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:115)
	at android.view.View.performClick(View.java:6608)
	at android.view.View.performClickInternal(View.java:6585)
	at android.view.View.access$3100(View.java:785)
	at android.view.View$PerformClick.run(View.java:25921)
	at android.os.Handler.handleCallback(Handler.java:873)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:201)
	at android.app.ActivityThread.main(ActivityThread.java:6810)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.lifecycle.MutableLiveData" on path: DexPathList[[zip file "/data/app/com.plz.djaman.allsaver-Ajcrql0ZP_Kz1oCg-PDv2A==/base.apk"],nativeLibraryDirectories=["/data/app/com.plz.djaman.allsaver-Ajcrql0ZP_Kz1oCg-PDv2A==/lib/arm64, /system/lib64]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)
homeActivity.java

package com.plz.djaman.allsaver;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import android.widget.Toast;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;

public class homeActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment fragment = null;
                switch (item.getItemId()) {
                    case R.id.home:
                        Toast.makeText(getApplicationContext(), "Home", Toast.LENGTH_SHORT).show();
                        fragment = new homeFrag();
                        break;
                    case R.id.download:
                        Toast.makeText(getApplicationContext(), "download", Toast.LENGTH_SHORT).show();
                        fragment = new downloadFrag();
                        break;
                    case R.id.setting:
                        Toast.makeText(getApplicationContext(), "Settings", Toast.LENGTH_SHORT).show();
                        fragment = new settingFrag();
                        break;
                }

                return loadFragment(fragment);
            }

            private boolean loadFragment(Fagment fragment) {
                //switching fragment 
                if (fragment != null) {
                    getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.container, fragment)
                        .commit();
                    return true;
                }
                return false;
            }
        });
    }
}
Fragment

package com.plz.djaman.allsaver;
import android.util.AttributeSet;
import android.view.View;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.widget.TextView;
import androidx.fragment.app.Fragment;

public class downloadFrag extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //just change the fragment_dashboard
        //with the fragment you want to inflate
        //like if the class is HomeFragment it should have R.layout.home_fragment
        //if it is DashboardFragment it should have R.layout.fragment_dashboard
        return inflater.inflate(R.layout.download_frag, null);
    }
}

请注意,我已将代码中的HTML实体转义字符(如&quot;)还原为原始的双引号。如果您需要继续阅读或处理代码,请告诉我。

英文:

I Don't Why I'm getting error :-

>java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/MutableLiveData;
at androidx.fragment.app.Fragment.<init>(Fragment.java:254)
at com.plz.djaman.allsaver.settingFrag.<init>(settingFrag.java:18)
at com.plz.djaman.allsaver.homeActivity$100000000.onNavigationItemSelected(homeActivity.java:36)
at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:204)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:115)
at android.view.View.performClick(View.java:6608)
at android.view.View.performClickInternal(View.java:6585)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25921)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.lifecycle.MutableLiveData" on path: DexPathList[[zip file "/data/app/com.plz.djaman.allsaver-Ajcrql0ZP_Kz1oCg-PDv2A==/base.apk"],nativeLibraryDirectories=[/data/app/com.plz.djaman.allsaver-Ajcrql0ZP_Kz1oCg-PDv2A==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)

homeActivity.java

package com.plz.djaman.allsaver;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import android.widget.Toast;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
public class homeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.home:
Toast.makeText(getApplicationContext(), &quot;Home&quot;, Toast.LENGTH_SHORT).show();
fragment = new homeFrag();
break;
case R.id.download:
Toast.makeText(getApplicationContext(), &quot;download&quot;, Toast.LENGTH_SHORT).show();
fragment = new downloadFrag();
break;
case R.id.setting:
Toast.makeText(getApplicationContext(), &quot;Settings&quot;, Toast.LENGTH_SHORT).show();
fragment = new settingFrag();
break;
}
return loadFragment(fragment);
}
private boolean loadFragment(Fragment fragment) {
//switching fragment 
if (fragment != null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container, fragment)
.commit();
return true;
}
return false;
}
});
}
}

Fragment

package com.plz.djaman.allsaver;
import android.util.AttributeSet;
import android.view.View;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
public class downloadFrag extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//just change the fragment_dashboard
//with the fragment you want to inflate
//like if the class is HomeFragment it should have R.layout.home_fragment
//if it is DashboardFragment it should have R.layout.fragment_dashboard
return inflater.inflate(R.layout.download_frag, null);
}
}

答案1

得分: 1

"java.lang.NoClassDefFoundError" error,基本上是一个版本导入的问题,你应该尝试修改Gradle导入jar的版本。

英文:

like this " java.lang.NoClassDefFoundError " error , It's basically a version-import problem ,You should try to modify the version that your Gradle imports jar

huangapple
  • 本文由 发表于 2020年8月12日 17:12:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63373410.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定