0

私は何時間もこれに取り組んできましたが、引き出しがまったく表示されないようです。これが私のコードです。誰かがここで何が間違っているのか教えてくれるかもしれません...引き出しでアクティビティに到達するまで、アプリはエラーなしで実行され、その後クラッシュします。

これが私のコードです:

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.support.v7.app.ActionBarDrawerToggle;

public class FlavorListView extends ActionBarActivity  {

    //shared preference
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    private CharSequence mDrawerTitle;
    private CharSequence mTitle;


    @Override
    public boolean onCreateOptionsMenu(Menu action_setting) {
        //MenuInflater inflater = getMenuInflater();
        //inflater.inflate(R.menu.menu_welcome,action_setting);

        //drawer
        mTitle = mDrawerTitle = getTitle();
        mDrawerLayout = (DrawerLayout) findViewById(R.id.navigation_drawer);
        mDrawerToggle = new ActionBarDrawerToggle(FlavorListView.this, mDrawerLayout,
                R.string.drawer_open, R.string.drawer_close) {

            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getSupportActionBar().setTitle(mTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getSupportActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };

        // Set the drawer toggle as the DrawerListener
       mDrawerLayout.setDrawerListener(mDrawerToggle);
        return true;
    }

    /* Called whenever we call invalidateOptionsMenu() */
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
        //boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
        //menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        //return super.onPrepareOptionsMenu(menu);

        //drawer end

        return true;



    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_flavor);



        String[] select_flavor_list = {"Kansas City", "Memphis", "Texas", "North Carolina", "South Carolina","Alabama"};


        ListAdapter FlavorListAdapter = new ArrayAdapter<String>(this, R.layout.row_layout_flavor, R.id.flavor_text_view,
                select_flavor_list);

        ListView listView = (ListView) findViewById(R.id.listView);

        listView.setAdapter(FlavorListAdapter);


        //For list view selection, begin here...
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                //String flavorPicked = String.valueOf(parent.getItemAtPosition(position));

                FoodStyleDialog cdd = new FoodStyleDialog(FlavorListView.this);
                cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                cdd.show();
                return true;

            }
        });

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
                //GlobalClass flavorPref = ((GlobalClass)getApplicationContext());

                String flavorPicked = String.valueOf(adapterView.getItemAtPosition(position));

                if (flavorPicked.equals("Kansas City")) {
                    Intent intent = new Intent(FlavorListView.this, KansasCity.class);
                    startActivity(intent);
                    setContentView(R.layout.kansas_city);
                    Toast.makeText(FlavorListView.this, "Looks like " + flavorPicked +
                                    " style be your flavor! You can change your flavor anytime in the settings menu.",
                            Toast.LENGTH_LONG).show();


                }
                else if (flavorPicked.equals("Memphis")) {
                    Intent intent = new Intent(FlavorListView.this, KansasCity.class);
                    startActivity(intent);
                    setContentView(R.layout.kansas_city);
                    Toast.makeText(FlavorListView.this, "Looks like " + flavorPicked +
                                    " style be your flavor! You can change your flavor anytime in the settings menu.",
                            Toast.LENGTH_LONG).show();
                }

            }

        });

    }
}

を取得しjava.lang.NullPointerExceptionていますが、デバッガーは at (FlavorListView.java:57)which is atと言っていますmDrawerLayout.setDrawerListener(mDrawerToggle);

この行をコメントアウトすると、アプリは実行されますが、引き出しはありません...

助けてください。ありがとう :)

引き出しレイアウト xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/navigation_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/content_frame"
        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.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#ffff"/>
</android.support.v4.widget.DrawerLayout>

FlavorListView アクティビティ xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingBottom="16dp"
    android:paddingTop="16dp"
    tools:context=".FlavorListView"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="Choose Your Flavor"
        android:textAlignment="center"
        android:textSize="30sp"
        android:textStyle="bold"
        android:gravity="center_horizontal"
        />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:listSelector="@drawable/abc_list_pressed_holo_light" />
</LinearLayout>
4

2 に答える 2