这是我的FuzzyGridMenu代码。但每次我尝试获取模糊菜单时都会出现错误。我无法找到错误的位置。
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.goka.blurredgridmenu.GridMenu;
import com.goka.blurredgridmenu.GridMenuFragment;
import java.util.ArrayList;
import java.util.List;
/**
* Created by duSHAn maduSHAnka on 2016-01-25.
*/
public class Test3 extends AppCompatActivity {
private GridMenuFragment mGridMenuFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test3);
mGridMenuFragment = GridMenuFragment.newInstance(R.drawable.background);
findViewById(R.id.show_menu_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main_frame, mGridMenuFragment);
tx.addToBackStack(null);
tx.commit();
}
});
setupGridMenu();
mGridMenuFragment.setOnClickMenuListener(new GridMenuFragment.OnClickMenuListener() {
@Override
public void onClickMenu(GridMenu gridMenu, int position) {
Toast.makeText(Test3.this, "Title:" + gridMenu.getTitle() + ", Position:" + position,
Toast.LENGTH_SHORT).show();
}
});
}
private void setupGridMenu() {
List<GridMenu> menus = new ArrayList<>();
menus.add(new GridMenu("Home", R.drawable.n));
menus.add(new GridMenu("Calendar", R.drawable.nn));
menus.add(new GridMenu("Overview", R.drawable.nnn));
menus.add(new GridMenu("Groups", R.drawable.nnnn));
menus.add(new GridMenu("Lists", R.drawable.nnnnn));
menus.add(new GridMenu("Profile", R.drawable.nnnnnn));
mGridMenuFragment.setupMenu(menus);
}
@Override
public void onBackPressed() {
if (0 == getSupportFragmentManager().getBackStackEntryCount()) {
super.onBackPressed();
} else {
getSupportFragmentManager().popBackStack();
}
}
}
我在这里犯了错误吗?
这是我的XML文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Test3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
>
<Button
android:id="@+id/show_menu_button"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@android:color/white"
android:text="Show Menu"
android:textSize="18sp"
android:gravity="center"
android:layout_margin="16dp"
android:textColor="@android:color/black"
android:alpha="0.8"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
这是错误。 logcat的
03-02 13:02:40.453 17063-17063/? I/art: Late-enabling -Xcheck:jni
03-02 13:02:40.850 17063-17063/com.ceatkelanisrilanka.dushanmadushanka.ceat I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
03-02 13:02:40.998 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-02 13:02:41.009 17063-17063/com.ceatkelanisrilanka.dushanmadushanka.ceat D/Atlas: Validating map...
03-02 13:02:41.190 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
03-02 13:02:41.191 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-02 13:02:41.207 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
03-02 13:02:41.266 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat I/OpenGLRenderer: Initialized EGL, version 1.4
03-02 13:02:41.314 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat D/OpenGLRenderer: Enabling debug mode 0
03-02 13:02:41.334 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat W/EGL_emulation: eglSurfaceAttrib not implemented
03-02 13:02:41.334 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xef0358c0, error=EGL_SUCCESS
03-02 13:02:45.895 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat W/EGL_emulation: eglSurfaceAttrib not implemented
03-02 13:02:45.895 17063-17083/com.ceatkelanisrilanka.dushanmadushanka.ceat W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf3f73740, error=EGL_SUCCESS
03-02 13:02:47.479 17063-17063/com.ceatkelanisrilanka.dushanmadushanka.ceat D/AndroidRuntime: Shutting down VM
03-02 13:02:47.484 17063-17063/com.ceatkelanisrilanka.dushanmadushanka.ceat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ceatkelanisrilanka.dushanmadushanka.ceat, PID: 17063
android.view.InflateException: Binary XML file line #13: Error inflating class com.goka.blurredgridmenu.BlurringView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.goka.blurredgridmenu.GridMenuFragment.onCreateView(GridMenuFragment.java:39)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.goka.blurredgridmenu.GridMenuFragment.onCreateView(GridMenuFragment.java:39)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v8/renderscript/RenderScript;
at com.goka.blurredgridmenu.BlurringView.initializeRenderScript(BlurringView.java:112)
at com.goka.blurredgridmenu.BlurringView.<init>(BlurringView.java:54)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.goka.blurredgridmenu.GridMenuFragment.onCreateView(GridMenuFragment.java:39)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v8.renderscript.RenderScript" on path: DexPathList[[zip file "/data/app/com.ceatkelanisrilanka.dushanmadushanka.ceat-3/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.goka.blurredgridmenu.BlurringView.initializeRenderScript(BlurringView.java:112)
at com.goka.blurredgridmenu.BlurringView.<init>(BlurringView.java:54)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.goka.blurredgridmenu.GridMenuFragment.onCreateView(GridMenuFragment.java:39)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: android.support.v8.renderscript.RenderScript
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 26 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
我做错了什么?
答案 0 :(得分:0)
我知道回答这个问题为时已晚,但它可能会帮助那些面临同样问题的人。
如果您没有在应用程序模块的app文件夹中的 build.gradle 文件中定义“ renderscript ”,则会出现以下问题。 即可。按照图书馆制作者的指导原则。
android.view.InflateException: Binary XML file line #13: Error inflating class com.goka.blurredgridmenu.BlurringView
因此,您需要启用renderscript ,如下所示
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
}
注意:强>
如果您使用renderscriptTargetApi作为22,那么我很抱歉您将面临一个问题......
Renderscript support mode is not currently supported with renderscript target 21+
是的,这是一个 bug ,而且这个bug与renderscriptTargetApi相关
如何解决上述问题。
解决方案1: 您可以将renderscriptTargetApi定义为低于2,如:
renderscriptTargetApi 20
renderscriptSupportModeEnabled true
解决方案2: 与renderscriptTargetApi相关的错误已在gradle-plugin 2.1.0和Build-Tools 23.0.3中修复。因此你也可以试试这个。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
希望,这可能会帮助你和其他人。