Im 'Android + HoloEverywhere 앱에 서랍 메뉴를 구현하려고합니다.HoloEverywhere가있는 InflateException Listview
시작하려면 http://developer.android.com/training/implementing-navigation/nav-drawer.html에 설명 된 방법을 사용했습니다. 유일한 차이점은 org.holoeverywhere.widget.ListView 대신에 고전적인 ListView를 임포트한다는 것입니다.
import android.support.v4.app.FragmentManager;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.ViewById;
import org.holoeverywhere.app.Activity;
import org.holoeverywhere.widget.ArrayAdapter;
import org.holoeverywhere.widget.DrawerLayout;
import org.holoeverywhere.widget.ListView;
@EActivity(R.layout.activity_main)
public class MainActivity
extends Activity {
// Declare Variables
ActionBar mActionBar;
@ViewById(R.id.drawer_layout)
DrawerLayout mDrawer;
@ViewById(R.id.left_drawer)
ListView mDrawerList;
private String[] mPlanetTitles;
@AfterViews
protected void useElements() {
// Activate Navigation Mode Tabs
mActionBar = getSupportActionBar();
// Locate ViewPager in activity_main.xml
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
// Activate Fragment Manager
FragmentManager fm = getSupportFragmentManager();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles);
// Set the adapter for the list view
mDrawerList.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
}
그리고 내 activity_main.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<org.holoeverywhere.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</org.holoeverywhere.widget.DrawerLayout>
편집
drawer_list_item.xml :
여기 내 MainActivity입니다<!--
Copyright 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#fff"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
이 코드는 내 안에 행성 목록이있는 서랍을 표시합니다. 안드로이드 4.x 장치에서 잘 작동합니다. beoause HoloEverywhere 클래스가 사용되지 않습니다. 내가 줄 언급 경우
11-25 14:09:24.771: E/AndroidRuntime(21797): FATAL EXCEPTION: main
11-25 14:09:24.771: E/AndroidRuntime(21797): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.LayoutInflater._createView(LayoutInflater.java:382)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.LayoutInflater.onCreateView(LayoutInflater.java:594)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:444)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:529)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:488)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:184)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.ArrayAdapter.getView(ArrayAdapter.java:256)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.ListAdapterWrapper.getView(ListAdapterWrapper.java:83)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.AbsListView.obtainView(AbsListView.java:1519)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.ListView.makeAndAddView(ListView.java:1749)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.ListView.fillDown(ListView.java:674)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.ListView.fillFromTop(ListView.java:731)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.ListView.layoutChildren(ListView.java:1602)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.AbsListView.onLayout(AbsListView.java:1349)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.ListView.onLayout(ListView.java:552)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:714)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.LinearLayout.setChildFrame(LinearLayout.java:1126)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.LinearLayout.layoutVertical(LinearLayout.java:583)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.LinearLayout.onLayout(LinearLayout.java:1096)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.FrameLayout.onLayout(FrameLayout.java:342)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.layout(View.java:7320)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.ViewRoot.performTraversals(ViewRoot.java:1162)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.ViewRoot.handleMessage(ViewRoot.java:1882)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.os.Looper.loop(Looper.java:130)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.app.ActivityThread.main(ActivityThread.java:3701)
11-25 14:09:24.771: E/AndroidRuntime(21797): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 14:09:24.771: E/AndroidRuntime(21797): at java.lang.reflect.Method.invoke(Method.java:507)
11-25 14:09:24.771: E/AndroidRuntime(21797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
11-25 14:09:24.771: E/AndroidRuntime(21797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
11-25 14:09:24.771: E/AndroidRuntime(21797): at dalvik.system.NativeStart.main(Native Method)
11-25 14:09:24.771: E/AndroidRuntime(21797): Caused by: java.lang.reflect.InvocationTargetException
11-25 14:09:24.771: E/AndroidRuntime(21797): at java.lang.reflect.Constructor.constructNative(Native Method)
11-25 14:09:24.771: E/AndroidRuntime(21797): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.LayoutInflater._createView(LayoutInflater.java:358)
11-25 14:09:24.771: E/AndroidRuntime(21797): ... 41 more
11-25 14:09:24.771: E/AndroidRuntime(21797): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x10102fd a=-1}
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.content.res.Resources.loadDrawable(Resources.java:1692)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.view.View.<init>(View.java:1975)
11-25 14:09:24.771: E/AndroidRuntime(21797): at android.widget.TextView.<init>(TextView.java:370)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.TextView.<init>(TextView.java:133)
11-25 14:09:24.771: E/AndroidRuntime(21797): at org.holoeverywhere.widget.TextView.<init>(TextView.java:129)
11-25 14:09:24.771: E/AndroidRuntime(21797): ... 44 more
11-25 14:09:24.831: W/ActivityManager(265): Force finishing activity com.board/.ui.activity.MainActivity_
11-25 14:09:25.341: W/ActivityManager(265): Activity pause timeout for HistoryRecord{2b3d55d8 com.board/.ui.activity.MainActivity_}
11-25 14:09:34.461: D/dalvikvm(21486): GC_EXPLICIT freed 52K, 49% free 2759K/5379K, external 1685K/2133K, paused 94ms
11-25 14:09:35.391: W/ActivityManager(265): Activity destroy timeout for HistoryRecord{2b3d55d8 com.board/.ui.activity.MainActivity_}
11-25 14:09:39.471: D/dalvikvm(21499): GC_EXPLICIT freed 302K, 45% free 3316K/6023K, external 1757K/2133K, paused 106ms
11-25 14:09:44.461: D/dalvikvm(21544): GC_EXPLICIT freed 143K, 48% free 2862K/5447K, external 1685K/2133K, paused 95ms
11-25 14:09:49.471: D/dalvikvm(21578): GC_EXPLICIT freed 806K, 49% free 3462K/6663K, external 1685K/2133K, paused 108ms
11-25 14:09:59.291: D/dalvikvm(7039): GC_EXPLICIT freed 6K, 46% free 3389K/6215K, external 1685K/2133K, paused 138ms
11-25 14:10:00.131: D/dalvikvm(1091): GC_EXPLICIT freed 3K, 49% free 2786K/5379K, external 1845K/2133K, paused 83ms
11-25 14:10:00.181: D/dalvikvm(343): GC_CONCURRENT freed 777K, 54% free 3267K/7047K, external 2542K/3017K, paused 2ms+9ms
11-25 14:10:00.201: D/dalvikvm(1091): GC_EXPLICIT freed 7K, 49% free 2788K/5379K, external 1981K/2133K, paused 28ms
11-25 14:10:04.161: D/SntpClient(265): request time failed: java.net.SocketTimeoutException: Try again
11-25 14:10:05.331: D/dalvikvm(21245): GC_EXPLICIT freed 179K, 50% free 3314K/6535K, external 1685K/2133K, paused 123ms
을 : 내 MainActivity에서
mDrawerList.setAdapter(adapter);
을가 2.X에서 실행, 나는 빈 서랍을 얻을 그러나 2.X에 다음과 같은 예외로 개방 충돌합니다.
게시물 R.layout.drawer_list_item xml 파일. 그 오류가 보인다 ... –
당신이 옳다! 나는이 파일을 체크하지도 않은 activity_main의 Listview에 너무 집중했다. "android : attr"속성을 제거하면 문제가 해결되었습니다. 내 게시물을 편집 했으므로 답장에 솔루션을 더 잘 설명 할 수있게 할 것입니다. – TrtG
@TrtG : 나는 같은 문제에 직면하고있다. 해결책을 게시 할 수 있는가? 감사. –