Pet*_*vdL 9 android android-fragments
我正在尝试使用向后兼容包和SDK级别10来扩展包含Fragment的布局.我将jar文件放在我项目的libs文件夹中.我扩展了FragmentActivity.
当我在XLarge屏幕设备上运行API级别11时,它完全可以正常工作.
当我退回到针对级别10进行编译并在正常大小的屏幕上运行时,我在创建新活动并使其中的片段膨胀时失败.
引起:java.lang.ClassNotFoundException:loader中的android.view.fragment dalvik.system.PathClassLoader [/data/app/com.motoappsummitagenda-1.apk] 04-01 01:07:14.311 2870 2870 E AndroidRuntime:at dalvik .system.PathClassLoader.findClass(PathClassLoader.java:243)
所以它看起来像什么,某处正在寻找android.view.fragment,而不是兼容版本android.support.v4.app.Fragment.当然,在API级别10上找不到android.view.fragment.但是android.view.fragment来自哪里?
正在膨胀的XML是
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.motorapp.SessionFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sessionfragment">
</fragment>
Run Code Online (Sandbox Code Playgroud)
它的代码开始:
package com.motorapp;
import java.util.List;
import java.util.ListIterator;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.support.v4.app.*;
import android.support.v4.util.*;
import android.support.v4.*;
import android.support.v4.widget.*;
public class SessionFragment extends android.support.v4.app.Fragment {
Run Code Online (Sandbox Code Playgroud)
症状类似于这个问题,但我没有那些错误用兼容包android扩展 碎片
android.compatibility.v4.android-support-v4 jar文件位于Eclipse中我的构建路径下的Project> Properties> Java build path
我在清单中(我尝试过不同的名称变体).
在开始使用片段时,我首先在蜂窝设备上使用API 11,这一切都完美无缺.它是使用兼容性库来获取相同的代码(修改为使用稍微不同的兼容性API),我有这个问题.任何想法都会非常受欢迎.谢谢,彼得
小智 41
我刚刚在Android API 8机器(三星Galaxy S)中解决了这个问题.
请将Activity课程改为FragmentActivity.
public class FragmentLayout extends Activity {}
- >
public class FragmentLayout extends FragmentActivity {}
public static class DetailsActivity extends Activity {}
- >
public static class DetailsActivity extends FragmentActivity {}
最后
getFragmentManager()- >getSupportFragmentManager()
将android-support-v4.jar注册到Eclipse的引用库
把android-support-v4.jar放到你项目的{root目录}/libs目录下
从simple_list_item_activated_1更改为API 10枚举(例如:simple_list_item_1)
import android.support.v4.app.Fragment;
The*_*heo 15
我在兼容性库中遇到了同样错误的类问题,并尝试了上面提到的所有内容而没有运气.我终于明白了:我使用的是不正确的XML元素Fragment而不是正确的元素fragment.资本化似乎很重要.
| 归档时间: |
|
| 查看次数: |
20643 次 |
| 最近记录: |