我用滚动标签之间去单独片段的应用程序。 每个片段只显示预设的文字。 该文本将被格式化为良好的外观,虽然,所以我需要使用HTML解析器来得到它才能正常显示。 我很新的Java和Android的,所以我想我的布局可能是错的但是我难住了这个问题,我希望有人可以帮助! 应用程序崩溃的推出。 该字符串存在于字符串文件。
这是该片段:
public static class AboutMeFragment extends Fragment {
public AboutMeFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
textviewabout = (TextView)getActivity().findViewById(R.id.textviewabout);
textviewabout.setText(Html.fromHtml(getString(R.string.about_me)));
View rootView = inflater.inflate(R.layout.aboutme,
container, false);
return rootView;
}
}
而这(再次,很肯定这是不正确的)创建的TextView。
public class MainActivity extends FragmentActivity {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
static TextView textviewabout;
这是aboutme.xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textviewabout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:scrollbars = "vertical"
android:text="@string/about_me" />
</ScrollView>
这里是日志的猫:
03-15 18:38:11.332: E/Trace(30586): error opening trace file: No such file or directory (2)
03-15 18:38:11.722: W/dalvikvm(30586): threadid=1: thread exiting with uncaught exception (group=0x41094540)
03-15 18:38:11.802: E/AndroidRuntime(30586): FATAL EXCEPTION: main
03-15 18:38:11.802: E/AndroidRuntime(30586): java.lang.NullPointerException
03-15 18:38:11.802: E/AndroidRuntime(30586): at com.example.keiththomsonsicv.MainActivity$AboutMeFragment.onCreateView(MainActivity.java:142)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.View.measure(View.java:15286)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.View.measure(View.java:15286)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.View.measure(View.java:15286)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-15 18:38:11.802: E/AndroidRuntime(30586): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2230)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.View.measure(View.java:15286)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2105)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1262)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1492)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1160)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4682)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:738)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.Choreographer.doCallbacks(Choreographer.java:564)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.Choreographer.doFrame(Choreographer.java:532)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:723)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.os.Handler.handleCallback(Handler.java:615)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.os.Handler.dispatchMessage(Handler.java:92)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.os.Looper.loop(Looper.java:155)
03-15 18:38:11.802: E/AndroidRuntime(30586): at android.app.ActivityThread.main(ActivityThread.java:5520)
03-15 18:38:11.802: E/AndroidRuntime(30586): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 18:38:11.802: E/AndroidRuntime(30586): at java.lang.reflect.Method.invoke(Method.java:511)
03-15 18:38:11.802: E/AndroidRuntime(30586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
03-15 18:38:11.802: E/AndroidRuntime(30586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
03-15 18:38:11.802: E/AndroidRuntime(30586): at dalvik.system.NativeStart.main(Native Method)
关于me.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity$AboutMeFragment" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textviewabout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:scrollbars = "vertical"
android:text="textviewabout" />
</ScrollView>
</RelativeLayout>