0
我正在構建一款具有遊戲並通過藍牙將遊戲信息傳遞給第二臺無線多人遊戲設備的應用程序。現在我正在嘗試將藍牙和遊戲課程放在FragmentActivity課程中,以便在遊戲進行過程中實現無縫藍牙訪問。我能夠成功地通過片段加載遊戲,但出於某種原因,藍牙移植會引發錯誤。我嘗試過使用activity.setContentView()和inflater.inflate,我通常使用但我仍然得到持久性錯誤。有人可以告訴我如何解決我的問題>我已經包含了有問題的代碼和錯誤日誌輸出。在FragmentActivity中啓動類時出錯(java.lang.IllegalArgumentException:沒有找到id的視圖)
07-30 13:27:25.225 15076-15076/com.example.android.BluetoothChat E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.BluetoothChat/com.example.android.BluetoothChat.FragmentHolder}: java.lang.IllegalArgumentException: No view found for id 0x7f060001 for fragment BluetoothChat{41b2d4e0 #1 id=0x7f060001}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f060001 for fragment BluetoothChat{41b2d4e0 #1 id=0x7f060001}
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:823)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.BackStackRecord.run(BackStackRecord.java:635)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
at android.app.Activity.performStart(Activity.java:5017)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
... 11 more
07-30 13:28:51.565 13981-13981/? E/APKInstallReceiver: context = [email protected], intent.getAction() = android.intent.action.PACKAGE_REMOVED, intent.getDataString() = package:com.example.android.BluetoothChat
07-30 13:28:51.825 13981-13981/? E/APKInstallReceiver: context = [email protected], intent.getAction() = android.intent.action.PACKAGE_ADDED, intent.getDataString() = package:com.example.android.BluetoothChat
07-30 13:28:56.305 15215-15215/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.BluetoothChat/com.example.android.BluetoothChat.FragmentHolder}: java.lang.IllegalArgumentException: No view found for id 0x7f060001 for fragment BluetoothChat{418a7730 #1 id=0x7f060001}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f060001 for fragment BluetoothChat{418a7730 #1 id=0x7f060001}
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:823)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.BackStackRecord.run(BackStackRecord.java:635)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
at android.app.Activity.performStart(Activity.java:5017)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
... 11 more
View view;
Activity activity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if(D) Log.e(TAG, "+++ ON CREATE +++");
activity = getActivity();
// Set up the window layout
// activity.setContentView(R.layout.main);
view = inflater.inflate(R.layout.main,
container, false);
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// If the adapter is null, then Bluetooth is not supported
if (mBluetoothAdapter == null) {
Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show();
startActivity(new Intent(activity, StartGame.class));
// this.finish();
}
return view;
}
這是FragmenActivity部分(不是所有我的代碼,因此不告訴我,我缺少的括號內。
public class FragmentHolder extends FragmentActivity {
public static boolean menuHidden = true;
public static final int LEFT_FRAG = R.id.fragmentcontainerleft;
public static final int RIGHT_FRAG = R.id.fragmentcontainerright;
public static final int BOTTOM_FRAG = R.id.fragmentcontainerbottom;
Fragment menu, main, top;
View view;
Activity activity;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetooth_menu_frag);
if(savedInstanceState == null){
FragmentManager manager = getFragmentManager();
//Start transaction
FragmentTransaction transaction = manager.beginTransaction();
//Create fragments
menu = new BluetoothChat();
main = new StartGame();
// top = new TopFragment();
//Add fragments
transaction.add(RIGHT_FRAG,main);
transaction.add(LEFT_FRAG,menu);
// transaction.add(BOTTOM_FRAG,top);
transaction.commit();
}
if(!menuHidden){
ScrollView scrollview = (ScrollView)findViewById(R.id.fragleft);
scrollview.setVisibility(View.VISIBLE);
FrameLayout menuFrame = (FrameLayout)findViewById(R.id.fragmentcontainerleft);
menuFrame.setVisibility(View.VISIBLE);
}
}