相关疑难解决方法(0)

无法强制转换为android.app.Fragment

我只是想看看片段,我得到了一些愚蠢的东西...有我的SkippersActivity.java:

public class SkippersActivity extends Activity{
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    setContentView(R.layout.skippers_fragment);
 }
}
Run Code Online (Sandbox Code Playgroud)

还有我的skippers_fragment.xml:

 <?xml version="1.0" encoding="utf-8"?>
    <fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.arkezis.globedroid.SkippersFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/skippers_fragment">
    </fragment>
Run Code Online (Sandbox Code Playgroud)

还有我的SkippersFragment.xml:

public class SkippersFragment extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    View mainView = inflater.inflate(R.layout.skippers, container, false);      
    return mainView;
}   
Run Code Online (Sandbox Code Playgroud)

}

我的skippers.xml:

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >    
    <ListView android:id="@+id/list_skippers_all"
        android:layout_width="match_parent"
    android:layout_height="match_parent">
    </ListView>
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

为什么我得到:

04-30 13:45:16.355: E/AndroidRuntime(30077): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arkezis.globedroid/com.arkezis.globedroid.SkippersActivity}: android.view.InflateException: Binary XML …
Run Code Online (Sandbox Code Playgroud)

android

31
推荐指数
2
解决办法
4万
查看次数

使用Android兼容性库寻找错误的片段类

我正在尝试使用向后兼容包和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

我在清单中(我尝试过不同的名称变体). …

android android-fragments

9
推荐指数
3
解决办法
2万
查看次数

如何在Android支持库v7 rev23中使用首选项?

在我使用支持库v7的应用程序中,我想添加一个首选项屏幕.由于Google完全没有提供有关该主题的文档,因此我查找了Stack Overflow上其他地方发现的帖子.

所以这是我的项目:

activity_preferences.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:support="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/toolbar_default"/>

    <fragment
        android:name=".FragmentPreferences"
        name=".FragmentPreferences"
        android:tag=".FragmentPreferences"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

ActivityPreferences.java

package com.example.testandroidsupportv7;

import com.example.testandroidsupportv7.R;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class ActivityPreferences extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preferences);
    }

}
Run Code Online (Sandbox Code Playgroud)

FragmentPreferences.java

package com.example.testandroidsupportv7;

import com.example.testandroidsupportv7.R;
import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;

public class FragmentPreferences extends PreferenceFragmentCompat
{

    @Override
    public void onCreatePreferences(Bundle bundle, String s) {
        addPreferencesFromResource(R.xml.preferences);
    }

}
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

<activity
        android:name=".ActivityPreferences"
        android:label="@string/app_name"
        android:theme="@style/MyTheme.NoActionBar" …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-preferences android-support-library

-4
推荐指数
1
解决办法
3981
查看次数