ゲームがあり、ゲーム情報をBluetooth経由でワイヤレスマルチプレイヤー用の2番目のデバイスに通信するアプリを構築しています。現在、Bluetooth とゲームのクラスを FragmentActivity クラスに配置して、ゲームのプレイ中にシームレスな Bluetooth アクセスを可能にしようとしています。フラグメントを介してゲームを正常にロードできますが、何らかの理由で Bluetooth の移植でエラーがスローされます。通常使用する activity.setContentView() と inflater.inflate を使用してみましたが、それでも永続的なエラーが発生します。誰かが私の問題を解決する方法を教えてもらえますか>問題のあるコードとエラーログ出力を含めました。
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 = android.app.ReceiverRestrictedContext@41998db0, 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 = android.app.ReceiverRestrictedContext@41998db0, 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);
}
}