我在我的 IntelliJ 项目中设置支持 v7 GridLayout 库或在我的代码中正确引用它时遇到了麻烦。
我目前在我的项目中使用 ActionBarSherlock 和 Facebook 库,并以相同的方式设置了支持 GridLayout 库(在 src 文件夹中没有源,我告诉 IntelliJ 将项目目录用作 jar 文件夹)。一切看起来都很好,构建并部署到了我的测试设备,但是当我尝试扩展布局时,我的应用程序崩溃了。
09-17 17:07:43.916: ERROR/AndroidRuntime(4143): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainHostActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.GridLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.GridLayout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.decoderhq.indieshuffle.PlayerFragment.onCreateView(PlayerFragment.java:63)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:857)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:251)
at com.example.MainHostActivity.onCreate(MainHostActivity.java:58)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
... 11 more
Caused by: java.lang.ClassNotFoundException: android.support.v7.widget.GridLayout in loader dalvik.system.PathClassLoader[/data/app/com.example.MyApp.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.view.LayoutInflater.createView(LayoutInflater.java:466)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
... 30 more
IntelliJ 还告诉我,我的 GridLayout 在 XML 设计器中“此处不允许”,我无法在各种搜索引擎中找到任何帮助。我的布局(截断长度)如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
grid:columnCount="3"
grid:rowCount="2"
android:id="@+id/player_grid">
<!-- previous artist label button/view -->
<LinearLayout
android:id="@+id/prev_artist_label_layout"
android:background="@drawable/player_prev_artist_bg_full"
android:padding="10dp"
grid:layout_column="0"
grid:layout_row="0">
<TextView
android:id="@+id/prev_artist_label"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:singleLine="true"
style="@style/PlayerArtistText"
android:ellipsize="end"/>
<ImageView
android:id="@+id/prev_artist_label_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"/>
</LinearLayout>
<!-- more cells in the grid [truncated for length] -->
</android.support.v7.widget.GridLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/player_grid">
<TextView
android:id="@+id/curr_time_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="@style/PlayerTimeLabels"
android:text="00:00"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"/>
<SeekBar
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/seek_bar"/>
<TextView
android:id="@+id/duration_time_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="@style/PlayerTimeLabels"
android:text="00:00"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</RelativeLayout>
Coles 备注:我在 RelativeLayout 中有一个支持 GridLayout 和一个位于顶部的 LinearLayout,锚定在 RelativeLayout 的底部。
日志表明我错过了一门课。我希望我只是没有正确设置图书馆,因为我想不出它还能是什么。希望有一些 IntelliJ/Android 知识的人可以为我指明正确的方向。
如果这个问题缺少一些信息,请放轻松 - 这是我第一次尝试使用 stackoverflow 寻求帮助。
提前致谢