这是Activity中的代码。片段改变了。应用程序可在平板电脑上运行,但可以在智能手机上使用(请参阅注释行)。尝试/捕捉不起作用。平板电脑的Android版本为4.2,智能手机的版本为4.4。
这是什么?
The code:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Check to see if we have a frame in which to embed the details
// fragment directly in the containing UI.
View detailsFrame = getActivity().findViewById(R.id.details);
mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
// Restore last state for checked position.
mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
}
Fragment f = map.get(mCurCheckPosition);
f = new DeviceUARTFragment(getActivity() , ftD2xx);
map.put(mCurCheckPosition, f);
Bundle args = new Bundle();
args.putInt("index", mCurCheckPosition);
f.setArguments(args);
currentFragment = f;
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.details, f);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit(); /* here application crashes */
old_index = currect_index;
}
logcat的:
11-19 05:37:58.310: E/FragmentManager(1161): No view found for id 0x7f0700f2 <br>(com.ftdi.javad2xxdemo:id/details) for fragment DeviceUARTFragment{b1dc0c60 #1 id=0x7f0700f2}<br>
11-19 05:37:58.310: E/FragmentManager(1161): Activity state:<br>
11-19 05:37:58.330: E/FragmentManager(1161): Local Activity b1dc16f8 State:<br>
11-19 05:37:58.330: E/FragmentManager(1161): mResumed=false mStopped=false mFinished=false<br>
11-19 05:37:58.340: E/FragmentManager(1161): mLoadersStarted=false<br>
11-19 05:37:58.340: E/FragmentManager(1161): mChangingConfigurations=false<br>
11-19 05:37:58.360: E/FragmentManager(1161): mCurrentConfig={1.0 310mcc260mnc en_US ldltr sw360dp w598dp h335dp 320dpi nrml land finger qwerty/v/v -nav/h s.6}<br>
11-19 05:37:58.360: E/FragmentManager(1161): Active Fragments in b1dc17f8:<br>
11-19 05:37:58.360: E/FragmentManager(1161): #0: TitlesFragment{b1dea6f0 #0 id=0x7f0700f1}<br>
11-19 05:37:58.360: E/FragmentManager(1161): mFragmentId=#7f0700f1 mContainerId=#ffffffff <br>mTag=null<br>
11-19 05:37:58.360: E/FragmentManager(1161): mState=2 mIndex=0 mWho=android:fragment:0 <br><br>mBackStackNesting=0
11-19 05:37:58.360: E/FragmentManager(1161): mAdded=true mRemoving=false mResumed=false mFromLayout=true mInLayout=true
11-19 05:37:58.360: E/FragmentManager(1161): mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
11-19 05:37:58.360: E/FragmentManager(1161): mRetainInstance=false mRetaining=false mUserVisibleHint=true
11-19 05:37:58.360: E/FragmentManager(1161): mFragmentManager=FragmentManager{b1dc17f8 in <br>FragmentLayout{b1dc16f8}}
11-19 05:37:58.360: E/FragmentManager(1161): <br>mActivity=com.ftdi.javad2xxdemo.FragmentLayout@b1dc16f8<br>
11-19 05:37:58.360: E/FragmentManager(1161): mView=android.widget.FrameLayout{b1deadd8 V.E..... ......I. 0,0-0,0 #7f0700f1 app:id/titles}<br>
11-19 05:37:58.360: E/FragmentManager(1161): #1: DeviceUARTFragment{b1dc0c60 #1 id=0x7f0700f2}<br>
11-19 05:37:58.360: E/FragmentManager(1161): mFragmentId=#7f0700f2 mContainerId=#<br>
11-19 05:37:58.660: E/FragmentManager(1161): 7f0700f2 mTag=null<br>
11-19 05:37:58.770: E/FragmentManager(1161): mState=0 mIndex=1 mWho=android:fragment:1 <br>mBackStackNesting=0
11-19 05:37:58.770: E/FragmentManager(1161): mAdded=true mRemoving=false mResumed=false <br>mFromLayout=false mInLayout=false
11-19 05:37:58.770: E/FragmentManager(1161): mHidden=false mDetached=false mMenuVisible=true <br>mHasMenu=false
11-19 05:37:58.770: E/FragmentManager(1161): mRetainInstance=false mRetaining=false <br>mUserVisibleHint=true
11-19 05:37:58.770: E/FragmentManager(1161): mFragmentManager=FragmentManager{b1dc17f8 in <br>FragmentLayout{b1dc16f8}}
11-19 05:37:58.850: E/FragmentManager(1161): <br>mActivity=com.ftdi.javad2xxdemo.FragmentLayout@b1dc16f8
11-19 05:37:58.850: E/FragmentManager(1161): mArguments=Bundle[{index=0}]<br>
11-19 05:37:58.850: E/FragmentManager(1161): Added Fragments:<br>
11-19 05:37:58.850: E/FragmentManager(1161): #0: TitlesFragment{b1dea6f0 #0 id=0x7f0700f1}<br>
11-19 05:37:58.850: E/FragmentManager(1161): #1: DeviceUARTFragment{b1dc0c60 #1 id=0x7f0700f2}<br>
11-19 05:37:58.990: E/FragmentManager(1161): FragmentManager misc state:<br>
11-19 05:37:58.990: E/FragmentManager(1161): mActivity=com.ftdi.javad2xxdemo.FragmentLayout@b1dc16f8<br>
11-19 05:37:58.990: E/FragmentManager(1161): mContainer=android.app.Activity$1@b1dc1870<br>
11-19 05:37:58.990: E/FragmentManager(1161): mCurState=2 mStateSaved=false mDestroyed=false<br>
11-19 05:37:58.990: E/FragmentManager(1161): Looper (main, tid 1) {b1dba140}<br>
11-19 05:37:58.990: E/FragmentManager(1161): Message 0: { when=-1s408ms <br>callback=android.app.ListFragment$1 target=android.os.Handler }
11-19 05:37:58.990: E/FragmentManager(1161): (Total messages: 1, idling=false, quitting=false)<br>
11-19 05:37:59.130: D/AndroidRuntime(1161): Shutting down VM<br>
11-19 05:37:59.140: W/dalvikvm(1161): threadid=1: thread exiting with uncaught exception <br>(group=0xb1ae3ba8)
11-19 05:37:59.410: E/AndroidRuntime(1161): FATAL EXCEPTION: main<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): Process: com.ftdi.javad2xxdemo, PID: 1161<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): java.lang.RuntimeException: Unable to start activity <br>ComponentInfo{com.ftdi.javad2xxdemo/com.ftdi.javad2xxdemo.FragmentLayout}: <br>java.lang.IllegalArgumentException: No view found for id 0x7f0700f2 (com.ftdi.javad2xxdemo:id/details) for fragment DeviceUARTFragment{b1dc0c60 #1 id=0x7f0700f2}<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.ActivityThread.access$800(ActivityThread.java:135)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.os.Handler.dispatchMessage(Handler.java:102)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at android.os.Looper.loop(Looper.java:136)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at android.app.ActivityThread.main(ActivityThread.java:5017)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at java.lang.reflect.Method.invokeNative(Native <br>Method)
11-19 05:37:59.410: E/AndroidRuntime(1161): at java.lang.reflect.Method.invoke(Method.java:515)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at dalvik.system.NativeStart.main(Native Method)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): Caused by: java.lang.IllegalArgumentException: No view <br>found for id 0x7f0700f2 (com.ftdi.javad2xxdemo:id/details) for fragment <br>DeviceUARTFragment{b1dc0c60 #1 id=0x7f0700f2}
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.FragmentManagerImpl.moveToState(FragmentManager.java:882)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.BackStackRecord.run(BackStackRecord.java:684)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at <br>android.app.Activity.performStart(Activity.java:5240)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)<br>
11-19 05:37:59.410: E/AndroidRuntime(1161): ... 11 more
答案 0 :(得分:1)
我不确定,但似乎没有 id &#34; 详情&#34; (R.id.details
)在此屏幕上。
您使用R.id.details
替换Fragment
,但是,看起来,您在此行中输入了错误的ID
ft.replace(R.id.details, f);
可能,您为平板电脑使用不同的布局。尝试设置正确的ID。
希望,它会对你有帮助。