android.view.InflateException:二进制XML文件中第10行错误:充气类片段 [英] android.view.InflateException: Binary XML file line #10: Error inflating class fragment
问题描述
我创建的应用程序遵循教程 http://www.techotopia.com/index.php / Using_Fragments_in_Android _-_ A_Worked_Example
但我有一个错误。
LogCat中:
8月5日至2日:16:22.044:D / dalvikvm(1846):晚启用CheckJNI
八月5日至2日:16:22.080:D / AndroidRuntime(1846):关闭VM
八月5日至2日:16:22.080:W / dalvikvm(1846):主题ID = 1:螺纹未捕获的异常退出(组= 0xa4d81b20)
八月5日至2日:16:22.096:E / AndroidRuntime(1846年):致命异常:主要
八月5日至2日:16:22.096:E / AndroidRuntime(1846):工艺:com.example.myfragmentexample,PID:1846
八月5日至2日:16:22.096:E / AndroidRuntime(1846):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.myfragmentexample / com.example.myfragmentexample.MainActivity}:android.view.InflateException:二进制XML文件中第10行错误:充气类片段
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.ActivityThread.access $ 800(ActivityThread.java:135)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.os.Handler.dispatchMessage(Handler.java:102)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.os.Looper.loop(Looper.java:136)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.ActivityThread.main(ActivityThread.java:5017)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在java.lang.reflect.Method.invokeNative(本机方法)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在java.lang.reflect.Method.invoke(Method.java:515)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在dalvik.system.NativeStart.main(本机方法)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):android.view.InflateException:二进制XML文件中第10行错误:充气类片段产生的原因
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.view.LayoutInflater.inflate(LayoutInflater.java:492)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.view.LayoutInflater.inflate(LayoutInflater.java:397)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.view.LayoutInflater.inflate(LayoutInflater.java:353)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Activity.setContentView(Activity.java:1929)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在com.example.myfragmentexample.MainActivity.onCreate(MainActivity.java:12)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Activity.performCreate(Activity.java:5231)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):11 ...更多
八月5日至2日:16:22.096:E / AndroidRuntime(1846):android.app.Fragment $ InstantiationException:产生的原因无法实例片段com.example.fragmentexample.ToolbarFragment:确保类名称存在,是公开的,有一个空的构造是公
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Fragment.instantiate(Fragment.java:597)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Fragment.instantiate(Fragment.java:561)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Activity.onCreateView(Activity.java:4778)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):21 ...更多
八月5日至2日:16:22.096:E / AndroidRuntime(1846):抛出java.lang.ClassNotFoundException:产生的原因没有找到类com.example.fragmentexample.ToolbarFragment的路径:DexPathList [zip文件\"/data/app/com.example.myfragmentexample-1.apk\"],nativeLibraryDirectories=[/data/app-lib/com.example.myfragmentexample-1, /系统/ lib目录]
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在java.lang.ClassLoader.loadClass(ClassLoader.java:497)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在java.lang.ClassLoader.loadClass(ClassLoader.java:457)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):在android.app.Fragment.instantiate(Fragment.java:583)
八月5日至2日:16:22.096:E / AndroidRuntime(1846):24 ...更多
MainActivity.java:
包com.example.myfragmentexample;
进口android.os.Bundle;
进口android.support.v4.app.FragmentActivity;公共类MainActivity扩展FragmentActivity工具
ToolbarFragment.ToolbarListener { @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
}
公共无效onButtononClick(INT字体大小,字符串文本){
TextFragment textfragment =(TextFragment)getSupportFragmentManager()
.findFragmentById(R.id.text_fragment);
textfragment.zmienWlasciwosci(字号,文字); }}
activity_main.xml中:
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<片段
机器人:ID =@ + ID / toolbar_fragment
机器人:名字=com.example.fragmentexample.ToolbarFragment
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
工具:布局=@布局/ toolbar_fragment/> <片段
机器人:ID =@ + ID / text_fragment
机器人:名字=com.example.fragmentexample.TextFragment
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_centerVertical =真
工具:布局=@布局/ text_fragment/>< / RelativeLayout的>
ToolbarFragment.java:
包com.example.myfragmentexample;进口android.app.Activity;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.SeekBar;
进口android.widget.SeekBar.OnSeekBarChangeListener;公共类ToolbarFragment扩展片段器具
OnSeekBarChangeListener { 私有静态诠释seekvalue = 10;
私有静态的EditText的EditText; ToolbarListener activityCallback; 公共接口ToolbarListener {
公共无效onButtononClick(INT位置,字符串文本);
} @覆盖
公共无效onAttach(活动活动){
super.onAttach(活动);
尝试{
activityCallback =(ToolbarListener)活性;
}赶上(抛出ClassCastException E){
抛出新ClassCastException异常(activity.toString()
+必须实现ToolbarListener);
}
} @覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){ 查看查看= inflater.inflate(R.layout.toolbar_fragment,集装箱,
假); 的EditText =(EditText上)view.findViewById(R.id.editText);
搜索栏搜索栏=(搜索栏)view.findViewById(R.id.seekBar);
seekbar.setOnSeekBarChangeListener(本);
Button按钮=(按钮)view.findViewById(R.id.button);
button.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){
(五)buttonClicked; }
}); 返回视图。
} 公共无效buttonClicked(查看视图){
activityCallback.onButtononClick(seekvalue,edittext.getText()
的ToString()); } @覆盖
公共无效onProgressChanged(搜索栏为arg0,ARG1 INT,布尔ARG2){
seekvalue = ARG1; } @覆盖
公共无效onStartTrackingTouch(搜索栏为arg0){
// TODO自动生成方法存根 } @覆盖
公共无效onStopTrackingTouch(搜索栏为arg0){
// TODO自动生成方法存根 }}
toolbar_fragment.xml:
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的EditText
机器人:ID =@ + ID / EDITTEXT
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:layout_alignParentTop =真
机器人:layout_marginTop =16DP
机器人:EMS =10
安卓的inputType =TEXT>
< requestFocus的/>
< /&的EditText GT; <搜索栏
机器人:ID =@ + ID /搜索栏
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_below =@ + ID / EDITTEXT
机器人:layout_marginTop =14dp/> <按钮
机器人:ID =@ + ID /按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:layout_marginTop =17dp
机器人:layout_below =@ + ID /搜索栏
机器人:文字=@字符串/ BUTTON_TEXT/>< / RelativeLayout的>
TextFragment.java:
包com.example.myfragmentexample;进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.TextView;公共类TextFragment扩展片段{
私有静态的TextView TextView的; @覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){
查看查看= inflater.inflate(R.layout.text_fragment,集装箱,FALSE); 的TextView =(TextView中)view.findViewById(R.id.textView1); 返回视图。
} 公共无效zmienWlasciwosci(INT字体大小,字符串文本){
textview.setTextSize(字号);
textview.setText(文本);
}}
text_fragment.xml:
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:文字=@字符串/ text_label
机器人:textAppearance =:/>中的Android ATTR / textAppearanceLarge?< / RelativeLayout的>
AndroidManifest:
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.myfragmentexample
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =19/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.myfragmentexample.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>< /清单>
我读了很多关于此错误的职位,但我找不到什么错在我的code。我伸出FragmentActivity,进口v4.app。
致:抛出java.lang.ClassNotFoundException:没有找到类
在路径com.example.fragmentexample.ToolbarFragment:
DexPathList [zip文件
\"/data/app/com.example.myfragmentexample-1.apk\"],nativeLibraryDirectories=[/data/app-lib/com.example.myfragmentexample-1,
/系统/ lib目录]
块引用>这
的android:NAME =com.example.fragmentexample.ToolbarFragment
必须
的android:NAME =com.example.myfragmentexample.ToolbarFragment
为
原因包名
ToolbarFragment.java
是包com.example.myfragmentexample;
同样,对于
TextFragment
的android:NAME =com.example.myfragmentexample.TextFragment
i created app followed tutorial http://www.techotopia.com/index.php/Using_Fragments_in_Android_-_A_Worked_Example but i have a error.
LogCat:
05-02 08:16:22.044: D/dalvikvm(1846): Late-enabling CheckJNI 05-02 08:16:22.080: D/AndroidRuntime(1846): Shutting down VM 05-02 08:16:22.080: W/dalvikvm(1846): threadid=1: thread exiting with uncaught exception (group=0xa4d81b20) 05-02 08:16:22.096: E/AndroidRuntime(1846): FATAL EXCEPTION: main 05-02 08:16:22.096: E/AndroidRuntime(1846): Process: com.example.myfragmentexample, PID: 1846 05-02 08:16:22.096: E/AndroidRuntime(1846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfragmentexample/com.example.myfragmentexample.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.access$800(ActivityThread.java:135) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.os.Handler.dispatchMessage(Handler.java:102) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.os.Looper.loop(Looper.java:136) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.main(ActivityThread.java:5017) 05-02 08:16:22.096: E/AndroidRuntime(1846): at java.lang.reflect.Method.invokeNative(Native Method) 05-02 08:16:22.096: E/AndroidRuntime(1846): at java.lang.reflect.Method.invoke(Method.java:515) 05-02 08:16:22.096: E/AndroidRuntime(1846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 05-02 08:16:22.096: E/AndroidRuntime(1846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 05-02 08:16:22.096: E/AndroidRuntime(1846): at dalvik.system.NativeStart.main(Native Method) 05-02 08:16:22.096: E/AndroidRuntime(1846): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 05-02 08:16:22.096: E/AndroidRuntime(1846): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Activity.setContentView(Activity.java:1929) 05-02 08:16:22.096: E/AndroidRuntime(1846): at com.example.myfragmentexample.MainActivity.onCreate(MainActivity.java:12) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Activity.performCreate(Activity.java:5231) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 05-02 08:16:22.096: E/AndroidRuntime(1846): ... 11 more 05-02 08:16:22.096: E/AndroidRuntime(1846): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.fragmentexample.ToolbarFragment: make sure class name exists, is public, and has an empty constructor that is public 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Fragment.instantiate(Fragment.java:597) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Fragment.instantiate(Fragment.java:561) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Activity.onCreateView(Activity.java:4778) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689) 05-02 08:16:22.096: E/AndroidRuntime(1846): ... 21 more 05-02 08:16:22.096: E/AndroidRuntime(1846): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.fragmentexample.ToolbarFragment" on path: DexPathList[[zip file "/data/app/com.example.myfragmentexample-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfragmentexample-1, /system/lib]] 05-02 08:16:22.096: E/AndroidRuntime(1846): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 05-02 08:16:22.096: E/AndroidRuntime(1846): at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 05-02 08:16:22.096: E/AndroidRuntime(1846): at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.Fragment.instantiate(Fragment.java:583) 05-02 08:16:22.096: E/AndroidRuntime(1846): ... 24 more
MainActivity.java:
package com.example.myfragmentexample; import android.os.Bundle; import android.support.v4.app.FragmentActivity; public class MainActivity extends FragmentActivity implements ToolbarFragment.ToolbarListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onButtononClick(int fontsize, String text) { TextFragment textfragment = (TextFragment) getSupportFragmentManager() .findFragmentById(R.id.text_fragment); textfragment.zmienWlasciwosci(fontsize, text); } }
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <fragment android:id="@+id/toolbar_fragment" android:name="com.example.fragmentexample.ToolbarFragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" tools:layout="@layout/toolbar_fragment" /> <fragment android:id="@+id/text_fragment" android:name="com.example.fragmentexample.TextFragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" tools:layout="@layout/text_fragment" /> </RelativeLayout>
ToolbarFragment.java:
package com.example.myfragmentexample; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; public class ToolbarFragment extends Fragment implements OnSeekBarChangeListener { private static int seekvalue = 10; private static EditText edittext; ToolbarListener activityCallback; public interface ToolbarListener { public void onButtononClick(int position, String text); } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { activityCallback = (ToolbarListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement ToolbarListener"); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.toolbar_fragment, container, false); edittext = (EditText) view.findViewById(R.id.editText); SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekBar); seekbar.setOnSeekBarChangeListener(this); Button button = (Button) view.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { buttonClicked(v); } }); return view; } public void buttonClicked(View view) { activityCallback.onButtononClick(seekvalue, edittext.getText() .toString()); } @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { seekvalue = arg1; } @Override public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } }
toolbar_fragment.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentTop="true" android:layout_marginTop="16dp" android:ems="10" android:inputType="text"> <requestFocus /> </EditText> <SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText" android:layout_marginTop="14dp" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="17dp" android:layout_below="@+id/seekBar" android:text="@string/button_text" /> </RelativeLayout>
TextFragment.java:
package com.example.myfragmentexample; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class TextFragment extends Fragment { private static TextView textview; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.text_fragment, container, false); textview = (TextView) view.findViewById(R.id.textView1); return view; } public void zmienWlasciwosci (int fontsize, String text){ textview.setTextSize(fontsize); textview.setText(text); } }
text_fragment.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/text_label" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfragmentexample" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.myfragmentexample.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
I read a lot of posts about this error, but i couldn't find something wrong in my code. I extends FragmentActivity, import v4.app.
解决方案Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.fragmentexample.ToolbarFragment" on path: DexPathList[[zip file "/data/app/com.example.myfragmentexample-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfragmentexample-1, /system/lib]]
This
android:name="com.example.fragmentexample.ToolbarFragment"
Must be
android:name="com.example.myfragmentexample.ToolbarFragment"
cause package name for
ToolbarFragment.java
ispackage com.example.myfragmentexample;
Similarly for
TextFragment
android:name="com.example.myfragmentexample.TextFragment"
这篇关于android.view.InflateException:二进制XML文件中第10行错误:充气类片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!