我正在做地图应用程序,我遇到了一些问题。 有人知道我的代码发生了什么吗?
ERROR
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: FATAL EXCEPTION: main
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: Process: com.onemap.activities, PID: 28673
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.onemap.activities/com.onemap.activities.OneMap}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.TextView
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:156)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.os.Looper.loop(Looper.java:157)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5872)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.TextView
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:620)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at com.onemap.fragments.MainMenu.onCreateView(MainMenu.java:88)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1965)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1047)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1237)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1339)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2295)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:375)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:1997)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at com.onemap.activities.OneMap.onCreate(OneMap.java:57)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5312)
10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
ONEMAP.java
setContentView(R.layout.onemap);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onemap);
AppUtilities.init(this);
favDB = new FavouritesDBHandler(AppUtilities.getContext());
this.scrollView = (SlidingMenu) findViewById(R.id.mScrollView);
View mainContent = this.scrollView.getMainContent();
OnClickListener clickListener = getClickListener();
OnLongClickListener longClickListener = getLongClickListener();
mainContent.findViewById(R.id.mScreenToggle).setOnClickListener(clickListener);
JewelContainer jewelContainer = (JewelContainer) mainContent.findViewById(R.id.jewel_container);
jewelContainer.setOnClickListener(clickListener);
jewelContainer.setOnLongClickListener(longClickListener);
LotViewSlider lotSlider = (LotViewSlider) mainContent.findViewById(R.id.mSeekLot);
lotSlider.setOnSeekBarChangeListener(getLotSliderListener());
lotSlider.setVisibility(View.INVISIBLE);
this.mMapView = (MapView) findViewById(R.id.mMapView);
this.mMapView.setOnStatusChangedListener(OneMapStatusListener.getInstance());
this.mMapView.setOnSingleTapListener(getSingleTapListener());
this.mMapView.setOnLongPressListener(getLongPressListener());
this.mMapView.setCalloutClickListener(getClickListener());
this.mMapView.getCallout().setMaxWidth(550);
}
MAINMENU.java
inflater.inflate(R.layout.menu_main, rl);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = super.onCreateView(inflater, container, savedInstanceState);
RelativeLayout rl = (RelativeLayout) v.findViewById(R.id.menu_content);
inflater.inflate(R.layout.menu_main, rl);
ListView menuList = (ListView) rl.findViewById(R.id.menu_list);
menuList.setOnItemClickListener(this);
menuList.setOnScrollListener(this);
ViewHolder viewHolder = new ViewHolder();
viewHolder.arrowUp = (ImageView) rl.findViewById(R.id.iv_arrow_up);
viewHolder.arrowDown = (ImageView) rl.findViewById(R.id.iv_arrow_down);
menuList.setTag(viewHolder);
MenuItem[] arrayMenuItem = new MenuItem[5];
arrayMenuItem[0] = new MenuItem(0, "Services", R.mipmap.ic_menu_title_service);
arrayMenuItem[1] = new MenuItem(1, getString(R.string.get_directions), R.mipmap.ic_directions);
arrayMenuItem[2] = new MenuItem(2, getString(R.string.amenities), R.mipmap.ic_amenities);
arrayMenuItem[3] = new MenuItem(3, "Others", R.mipmap.ic_menu_title_other);
arrayMenuItem[4] = new MenuItem(4, getString(R.string.about), R.mipmap.ic_about);
menuList.setAdapter(new MenuAdapter(getActivity(), arrayMenuItem));
return v;
}
这是我的XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.onemap.widgets.MapView
xmlns:callout="http://schemas.android.com/apk/res/com.onemap.activities"
android:id="@id/mMapView"
calloutStyle="@xml/callout_style"
initExtent="29454.233386372267 39831.55546813806 30038.01821247406 40758.313879574656"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
callout:layout="@layout/callout" />
<ProgressBar
android:id="@id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
<com.onemap.widgets.SlidingMenu
xmlns:menu="http://schemas.android.com/apk/res/com.onemap.activities"
android:id="@id/mScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
menu:main_content="@id/mainContainer"
menu:menu_content="@id/menuContainer"
menu:menu_handle="@id/handle"
menu:menu_marginRight="@dimen/menu_margin_r">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment
android:id="@id/menuContainer"
class="com.onemap.fragments.MainMenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:tag="MainMenu"
tools:layout="@layout/menu_main" />
<include
android:id="@id/mainContainer"
layout="@layout/widgets" />
</LinearLayout>
</com.onemap.widgets.SlidingMenu>
</RelativeLayout>
&#13;
答案 0 :(得分:0)
您设置视图的方式是错误的,我为您调整了代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//set the main view change hello_world to the correct layout_name.xml file
View v = inflater.inflate(R.layout.hello_world, container, false);
//set the other views
ViewHolder viewHolder = new ViewHolder();
viewHolder.arrowUp = (ImageView) v.findViewById(R.id.iv_arrow_up);
viewHolder.arrowDown = (ImageView) v.findViewById(R.id.iv_arrow_down);
ListView menuList = (ListView) v.findViewById(R.id.menu_list);
menuList.setOnItemClickListener(this);
menuList.setOnScrollListener(this);
menuList.setTag(viewHolder);
MenuItem[] arrayMenuItem = new MenuItem[5];
arrayMenuItem[0] = new MenuItem(0, "Services", R.mipmap.ic_menu_title_service);
arrayMenuItem[1] = new MenuItem(1, getString(R.string.get_directions), R.mipmap.ic_directions);
arrayMenuItem[2] = new MenuItem(2, getString(R.string.amenities), R.mipmap.ic_amenities);
arrayMenuItem[3] = new MenuItem(3, "Others", R.mipmap.ic_menu_title_other);
arrayMenuItem[4] = new MenuItem(4, getString(R.string.about), R.mipmap.ic_about);
menuList.setAdapter(new MenuAdapter(getActivity(), arrayMenuItem));
return v;
}
视图持有者代码应该移动到您的自定义适配器MenuAdapter