0
我正在嘗試創建一個教程應用程序。我得到一個消息,說Android studio導航抽屜 - 預期表情
表達預計
下
case 2:
Activity = new Lesson111();
break;
注意 - 這是不是我的主要活動的整個代碼。但是,當我改變
case 2:
fragment = new Lesson111();
break;
到
case 2:
Activity = new Lesson111();
break;
問題開始這裏是我的Main.Activity:
public class NavigationActivity extends FragmentActivity {
private DrawerLayout mDrawerLayout;
ImageView home;
Fragment fragment = null;
TextView appname;
ExpandableListView expListView;
HashMap<String, List<String>> listDataChild;
ExpandableListAdapter listAdapter;
List<String> listDataHeader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation);
home = (ImageView)findViewById(R.id.home);
home.setOnClickListener(homeOnclickListener);
appname = (TextView)findViewById(R.id.appname);
setUpDrawer();
}
/**
*
* Get the names and icons references to build the drawer menu...
*/
private void setUpDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
mDrawerLayout.setDrawerListener(mDrawerListener);
expListView = (ExpandableListView) findViewById(R.id.lvExp);
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
fragment = new Lesson1();
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerLayout.closeDrawer(expListView);
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition) {
case 0:
switch (childPosition) {
case 0:
fragment = new Lesson1();
break;
case 1:
fragment = new Lesson11();
break;
case 2:
Activity = new Lesson111();
break;
default:
break;
}
break;
你還沒有初始化一個活動變量。試試像Activity activity = new Lesson111(); –
我試過你說的話。但是它說的是不兼容的類型。此外,「活動」灰顯。它也說 - 必需:android.app.Activity發現:com.android.pet.view.Lesson111 –
原因你沒有實際實例化一個活動實例。現在它只是掛在那裏。你想達到什麼目的?請更新您的問題,請更多信息請 –