我正在android studio中开发一个应用程序,其中包含一个我似乎无法开始工作的fragmentContainer
。我只是得到一个错误说:
Error:(20, 53) error: cannot find symbol variable fragmentContainer
代码如下:
package criminalintent.android.bignerdranch.com.criminalintentnew;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
/**
* This is the view-class. This Class is getting with the CrimeFragment controller.
*/
public class CrimeActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crime);
// Organize fragment addition to main UI :
FragmentManager fragManager = getSupportFragmentManager();
Fragment fragment = fragManager.findFragmentById(R.id.fragmentContainer); // this is where it starts to mention the error.
if (fragment == null) {
fragment = new CrimeFragment();
fragManager.beginTransaction().add(R.id.fragmentContainer, fragment).commit(); // also shows up as error.
}
}
}
知道为什么它不起作用? 提前致谢。