我想我已经做了一些事情来为我的片段添加一个MvxGridView,但我仍然得到Error inflating class Mvx.MvxGridView
或更确切地说ClassNotFoundException
,但为什么?
OS X上的Xamarin Studio,Cirrious.MvvmCross.Binding.Droid.dll
被引用。
我错过了什么?
我的主要活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:choiceMode="singleChoice"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
我用Fragment填充FrameLayout:
SupportFragmentManager.BeginTransaction()
.Replace(Resource.Id.content_frame, fragment)
.Commit();
我的片段:
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
this.HasOptionsMenu = true;
var ignored = base.OnCreateView (inflater, container, savedInstanceState);
var view = inflater.Inflate (Resource.Layout.fragment_main, null);
/* ... ... ... */
}
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxGridView
android:id="@+id/grid"
android:padding="@dimen/standard_padding"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
local:MvxBind="ItemsSource Stations; ItemClick PlayCommand"
local:MvxItemTemplate="@layout/item_station"
android:numColumns="@integer/station_columns"
android:stretchMode="columnWidth"
android:drawSelectorOnTop="true"
android:clipChildren="false"
android:clipToPadding="false"
android:horizontalSpacing="@dimen/standard_padding"
android:verticalSpacing="@dimen/standard_padding"
android:gravity="center"
android:fastScrollEnabled="false"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
android:smoothScrollbar="true" />
</LinearLayout>
堆栈跟踪:
Android.Views.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxGridView
at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00064] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:194
at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.LayoutInflater.cs:575
at MyApp.Droid.MainFragment.OnCreateView (Android.Views.LayoutInflater,Android.Views.ViewGroup,Android.OS.Bundle) [0x00019] in /Users/magnusjohansson/Projects/QuickApp/MyApp.Droid/Fragments/MainFragment.cs:46
at at Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (intptr,intptr,intptr,intptr,intptr) <IL 0x00026, 0x000ee>
at at (wrapper dynamic-method) object.4f99b429-b0b6-4522-936d-562081396c11 (intptr,intptr,intptr,intptr,intptr) <IL 0x00023, 0x00037>
at --- End of managed exception stack trace ---
at android.view.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxGridView
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at at MyApp.droid.MainFragment.n_onCreateView(Native Method)
at at MyApp.droid.MainFragment.onCreateView(MainFragment.java:39)
at at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
at at MyApp.droid.helpers.MvxActionBarEventSourceActivity.n_onStart(Native Method)
at at MyApp.droid.helpers.MvxActionBarEventSourceActivity.onStart(MvxActionBarEventSourceActivity.java:78)
at at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at at android.app.Activity.performStart(Activity.java:5241)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at at android.app.ActivityThread.access$800(ActivityThread.java:135)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:136)
at at android.app.ActivityThread.main(ActivityThread.java:5017)
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:515)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at at dalvik.system.NativeStart.main(Native Method)
at Caused by: java.lang.ClassNotFoundException: Didn't find class "Mvx.MvxGridView" on path: DexPathList[[zip file "/data/app/com.perfinica.MyApp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.perfinica.MyApp-1, /system/lib]]
at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at ... 28 more
答案 0 :(得分:0)
我遇到了同样的问题。我看到的是修改My Fragment类中的以下代码行来解决问题。
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.Inflate(Resource.Layout.fragment_main, container, false);
}
为:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignore = base.OnCreateView(inflater, container, savedInstanceState);
return this.BindingInflate(Resource.Layout.fragment_main, null);
}