2017-05-18 6 views
0

" 'navList'변수를 해결할 수 없습니다. '라는 오류가 발생합니다. 나는 navList를 찾을 수없는 이유를 이해하지 못한다. 누군가 내가 잘못 가고있는 것을 지적 할 수 있으면 감사 할 것입니다. 루키 질문에 대해 미안합니다.주 활동 오류 변수를 찾을 수 없습니다.

import android.app.Activity; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.app.ActionBar; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.content.Context; 
import android.os.Build; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.support.v4.widget.DrawerLayout; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 
import android.widget.ListView; 

public class MainActivity extends AppCompatActivity 
     implements NavigationDrawerFragment.NavigationDrawerCallbacks { 

/** 
* Fragment managing the behaviors, interactions and presentation of the navigation drawer. 
*/ 
private NavigationDrawerFragment mNavigationDrawerFragment; 

/** 
* Used to store the last screen title. For use in {@link #restoreActionBar()}. 
*/ 
private CharSequence mTitle; 

private ListView mDrawerList; 

private ArrayAdapter<String> mAdapter; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mNavigationDrawerFragment = (NavigationDrawerFragment) 
      getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); 
    mTitle = getTitle(); 

    // Set up the drawer. 
    mNavigationDrawerFragment.setUp(
      R.id.navigation_drawer, 
      (DrawerLayout) findViewById(R.id.drawer_layout)); 

    mDrawerList = (ListView)findViewById(R.id.navList); 

} 

편집 -

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. --> 

<!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
<FrameLayout android:id="@+id/container" android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- android:layout_gravity="start" tells DrawerLayout to treat 
    this as a sliding drawer on the left side for left-to-right 
    languages and on the right side for right-to-left languages. 
    If you're not building against API 17 or higher, use 
    android:layout_gravity="left" instead. --> 
<!-- The drawer is given a fixed width in dp and extends the full height of 
    the container. --> 
<fragment android:id="@+id/navigation_drawer" 
    android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent" 
    android:layout_gravity="start" android:name="com.yamini.nav.NavigationDrawerFragment" 
    tools:layout="@layout/fragment_navigation_drawer" /> 

+0

activity_main.xml을 게시하십시오. 귀하의 android : id가 잘못되었을 수 있습니다. – Aravindraj

+0

XML 코드를 게시하십시오 activity_main.xml – sasikumar

+0

XML에'navList'가 없습니다. –

답변

0

이 XML 파일에는 navList 없다

activity_main.xml

코드의 줄을 보면 조각을 사용하고있는 것처럼 보입니다.

NavigationDrawerFragment 대신 루트보기에서 코드를 호출 해보세요.

// inside NavigationDrawerFragment class 
mDrawerList = (ListView)MyRootView.findViewById(R.id.navList); 
+0

아직 컴파일러 오류가 발생했습니다 – chocolateAndMath

+0

@chocolateAndMath'MyRootView'를 실제 루트보기로 변경했다고 가정합니다. 어떤 오류가 보이나요? – Doomsknight