有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓 java。lang空点异常

上面说第71行有错误,但我能猜出是什么错误,有什么灵魂愿意帮助我?谢谢

我的问题是,当我点击Main活动上的foodbutton时,系统崩溃。但是logcat显示了食物中的错误。java,这是另一个页面

这是代码

package com.yiqiexample.cabincrew;


import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import 安卓.app.Activity;
import 安卓.app.ListActivity;
import 安卓.app.ProgressDialog;
import 安卓.content.Intent;
import 安卓.os.AsyncTask;
import 安卓.os.Bundle;
import 安卓.view.View;
import 安卓.view.View.OnClickListener;
import 安卓.widget.AdapterView;
import 安卓.widget.Button;
import 安卓.widget.CheckBox;
import 安卓.widget.EditText;
import 安卓.widget.ListAdapter;
import 安卓.widget.ListView;
import 安卓.widget.SimpleAdapter;
//import 安卓.widget.ImageView;
import 安卓.widget.TextView;
import 安卓.widget.Toast;
import 安卓.widget.AdapterView.OnItemClickListener;



public class Food extends ListActivity 
    implements OnClickListener {
    // Progress Dialog
        private ProgressDialog pDialog;

    //testing on Emulator:
     private static final String READ_COMMENTS_URL = "http://10.0.2.2/pbda2/foodordered.php";
    // private CheckBox chkFood, chkDrinks, chkServices;
      //private Button btnDisplay, chkClear, deliever, chkClearFood, fooddeliever, drinksdeliever, servicesdeliever, chkClearDrinks, chkClearServices;
      //private TextView clearThis,orderdisplay, clearThisFood, foodorderdisplay, drinksorderdisplay, servicesorderdisplay, clearThisDrinks, clearThisServices;

      private static final String TAG_SUCCESS = "success";
      private static final String TAG_POSTS = "posts";
        private static final String TAG_SEATNUMBER = "seatnumber";
        private static final String TAG_FOODORDERED = "foodordered";
        //it's important to note that the message is both in the parent branch of 
        //our JSON tree that displays a "Post Available" or a "No Post Available" message,
        //and there is also a message for each individual post, listed under the "posts"
        //category, that displays what the user typed as their message.

      //An array of all of our comments
        private JSONArray mComments = null;
        //manages all of our comments in a list.
        private ArrayList<HashMap<String, String>> mCommentList;



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



        View v = findViewById(R.id.backmain);
        //set event listener
            v.setOnClickListener(this);

            View z = findViewById(R.id.drinksbtn);
            //set event listener
                z.setOnClickListener(this);

                View x = findViewById(R.id.servicebtn);
                //set event listener
                    x.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        //loading the comments via AsyncTask
        new LoadComments().execute();
    }


    /**
     * Retrieves recent post data from the server.
     */
    public void updateJSONdata() {

        // Instantiate the arraylist to contain all the JSON data.
        // we are going to use a bunch of key-value pairs, referring
        // to the json element name, and the content, for example,
        // message it the tag, and "I'm awesome" as the content..

        mCommentList = new ArrayList<HashMap<String, String>>();

        // Bro, it's time to power up the J parser 
        JSONParser jParser = new JSONParser();
        // Feed the beast our comments url, and it spits us
        //back a JSON object.  Boo-yeah Jerome.
        JSONObject json = jParser.getJSONFromUrl(READ_COMMENTS_URL);

        //when parsing JSON stuff, we should probably
        //try to catch any exceptions:
        try {

            //I know I said we would check if "Posts were Avail." (success==1)
            //before we tried to read the individual posts, but I lied...
            //mComments will tell us how many "posts" or comments are
            //available
            mComments = json.getJSONArray(TAG_POSTS);

            // looping through all posts according to the json object returned
            for (int i = 0; i < mComments.length(); i++) {
                JSONObject c = mComments.getJSONObject(i);

                //gets the content of each tag
                String seatnumber = c.getString(TAG_SEATNUMBER);
                String foodordered = c.getString(TAG_FOODORDERED);



                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                map.put(TAG_SEATNUMBER, seatnumber);
                map.put(TAG_FOODORDERED, foodordered);


                // adding HashList to ArrayList
                mCommentList.add(map);

                //annndddd, our JSON data is up to date same with our array list
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }









    @Override
            public void onClick(View arg0) {
        if(arg0.getId() == R.id.backmain){
            //define a new Intent for the second Activity
            Intent intent = new Intent(this,MainActivity.class);

            //start the second Activity
            this.startActivity(intent);
            }
        if(arg0.getId() == R.id.drinksbtn){
            //define a new Intent for the second Activity
            Intent intent = new Intent(this,Drinks.class);

            //start the second Activity
            this.startActivity(intent);
            }
        if(arg0.getId() == R.id.servicebtn){
            //define a new Intent for the second Activity
            Intent intent = new Intent(this,Services.class);

            //start the second Activity
            this.startActivity(intent);
            }



    }

    /**
     * Inserts the parsed data into the listview.
     */
    private void updateList() {
        // For a ListActivity we need to set the List Adapter, and in order to do
        //that, we need to create a ListAdapter.  This SimpleAdapter,
        //will utilize our updated Hashmapped ArrayList, 
        //use our single_post xml template for each item in our list,
        //and place the appropriate info from the list to the
        //correct GUI id.  Order is important here.

        ListAdapter adapter = new SimpleAdapter(this, mCommentList,
                R.layout.single_post, new String[] { TAG_SEATNUMBER, TAG_FOODORDERED
                //TAG_DRINKSORDERED, TAG_SERVICES
                         }, new int[] { R.id.seatnumber, R.id.orders
                //R.id.drinkstv, R.id.servicestv,


         });



        // I shouldn't have to comment on this one:
        setListAdapter(adapter);

        // Optional: when the user clicks a list item we 
        //could do something.  However, we will choose
        //to do nothing...
        ListView lv = getListView();    
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                // This method is triggered if an item is click within our
                // list. For our example we won't be using this, but
                // it is useful to know in real life applications.

            }
        });
    }   




    public class LoadComments extends AsyncTask<Void, Void, Boolean> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Food.this);
            pDialog.setMessage("Loading orders...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected Boolean doInBackground(Void... arg0) {
            //we will develop this method in version 2
            updateJSONdata();
            return null;

        }


        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            pDialog.dismiss();
          //we will develop this method in version 2
            updateList();
        }
    }


}

这是主页的编码

package com.yiqiexample.cabincrew;

import 安卓.os.Bundle;
import 安卓.app.Activity;
import 安卓.content.Intent;
import 安卓.view.Menu;
import 安卓.view.View;
import 安卓.view.View.OnClickListener;

public class MainActivity extends Activity 

        implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        View v = findViewById(R.id.foodbutton);
        //set event listener
            v.setOnClickListener(this);

       View x= findViewById(R.id.drinks);
            //set event listener
                x.setOnClickListener(this);

       View y = findViewById(R.id.services);
                //set event listener
                    y.setOnClickListener(this);
    }
    @Override
            public void onClick(View arg0) {
        if(arg0.getId() == R.id.foodbutton){
            //define a new Intent for the second Activity
            Intent intent = new Intent(this,Food.class);

            //start the second Activity
            this.startActivity(intent);
            }


        if(arg0.getId() == R.id.drinks){
            //define a new Intent for the second Activity
            Intent intent = new Intent(this,Drinks.class);

            //start the second Activity
            this.startActivity(intent);
            }

        if(arg0.getId() == R.id.services){
            //define a new Intent for the second Activity
            Intent intent = new Intent(this,Services.class);

            //start the second Activity
            this.startActivity(intent);
            }





    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

食物。xml

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools"
    xmlns:安卓1="http://schemas.安卓.com/apk/res/安卓"
    安卓1:id="@+id/bg2"
    安卓:layout_width="match_parent"
    安卓:layout_height="wrap_content"
    安卓1:background="#E0FFFF" >

    <Button
        安卓1:id="@+id/backmain"
        安卓1:layout_width="wrap_content"
        安卓1:layout_height="wrap_content"
        安卓1:layout_alignParentBottom="true"
        安卓1:layout_alignParentRight="true"
        安卓1:text="@string/backtomain" />

    <Button
        安卓1:id="@+id/servicesdelivered"
        安卓1:layout_width="wrap_content"
        安卓1:layout_height="wrap_content"
        安卓1:layout_above="@+id/foodbtn"
        安卓1:layout_alignLeft="@+id/backmain"
        安卓1:text="@string/servicesdelivered"
        安卓1:visibility="invisible" />
    <Button
        安卓:id="@+id/servicebtn"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentBottom="true"
        安卓:layout_marginLeft="358dp"
        安卓:layout_toRightOf="@+id/foodbutton"
        安卓:text="SERVICES" />

    <Button
        安卓1:id="@+id/foodbtn"
        安卓1:layout_width="wrap_content"
        安卓1:layout_height="wrap_content"
        安卓1:layout_alignParentBottom="true"
        安卓1:layout_marginBottom="23dp"
        安卓1:layout_marginRight="24dp"
        安卓1:text="DRINKS ORDERS" />


    <LinearLayout
        安卓:id="@+id/top_layover"
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentLeft="true"
        安卓:layout_alignParentTop="true"
        安卓:orientation="horizontal" >

        <TextView
            安卓1:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:layout_gravity="center"
            安卓:gravity="center"
            安卓:text="@string/foodtitle"
            安卓:textAppearance="?安卓:attr/textAppearanceLarge" />

    </LinearLayout>

    <ListView
        安卓:id="@安卓:id/list"
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:layout_below="@+id/top_layover"
        安卓1:layout_alignBottom="@+id/servicesdelivered"
        安卓:background="#fff"
        安卓:divider="@安卓:color/transparent"
        安卓:scrollbars="none" />

    <LinearLayout
        安卓:id="@+id/bottom_layover"
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentBottom="true"
        安卓:layout_alignParentLeft="true"
        安卓:orientation="horizontal"
        安卓:weightSum="2" >

        <LinearLayout
            安卓:layout_width="0dp"
            安卓:layout_height="wrap_content"
            安卓:layout_weight="1"
            安卓:orientation="vertical" >

        </LinearLayout>

        <LinearLayout
            安卓:layout_width="0dp"
            安卓:layout_height="wrap_content"
            安卓:layout_weight="1"
            安卓:orientation="vertical" >



        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

这是LOGCAT

11-03 04:23:36.974: W/dalvikvm(756): threadid=1: thread exiting with uncaught exception (group=0x41465700)
11-03 04:23:37.093: E/AndroidRuntime(756): FATAL EXCEPTION: main
11-03 04:23:37.093: E/AndroidRuntime(756): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yiqiexample.cabincrew/com.yiqiexample.cabincrew.Food}: java.lang.NullPointerException
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.ActivityThread.access$600(ActivityThread.java:141)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.os.Handler.dispatchMessage(Handler.java:99)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.os.Looper.loop(Looper.java:137)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.ActivityThread.main(ActivityThread.java:5103)
11-03 04:23:37.093: E/AndroidRuntime(756):  at java.lang.reflect.Method.invokeNative(Native Method)
11-03 04:23:37.093: E/AndroidRuntime(756):  at java.lang.reflect.Method.invoke(Method.java:525)
11-03 04:23:37.093: E/AndroidRuntime(756):  at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-03 04:23:37.093: E/AndroidRuntime(756):  at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-03 04:23:37.093: E/AndroidRuntime(756):  at dalvik.system.NativeStart.main(Native Method)
11-03 04:23:37.093: E/AndroidRuntime(756): Caused by: java.lang.NullPointerException
11-03 04:23:37.093: E/AndroidRuntime(756):  at com.yiqiexample.cabincrew.Food.onCreate(Food.java:71)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.Activity.performCreate(Activity.java:5133)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 04:23:37.093: E/AndroidRuntime(756):  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-03 04:23:37.093: E/AndroidRuntime(756):  ... 11 more
11-03 04:23:43.713: I/Process(756): Sending signal. PID: 756 SIG: 9
11-03 04:23:46.715: D/dalvikvm(895): GC_FOR_ALLOC freed 44K, 4% free 2600K/2708K, paused 57ms, total 60ms
11-03 04:23:46.753: I/dalvikvm-heap(895): Grow heap (frag case) to 4.941MB for 2457616-byte allocation
11-03 04:23:46.893: D/dalvikvm(895): GC_FOR_ALLOC freed 2K, 3% free 4998K/5112K, paused 130ms, total 130ms
11-03 04:23:47.793: D/gralloc_goldfish(895): Emulator without GPU emulation detected.
11-03 04:31:41.842: I/Choreographer(895): Skipped 125 frames!  The application may be doing too much work on its main thread.
11-03 04:31:42.284: I/Choreographer(895): Skipped 62 frames!  The application may be doing too much work on its main thread.
11-03 04:31:42.913: I/Choreographer(895): Skipped 71 frames!  The application may be doing too much work on its main thread.
11-03 04:32:15.008: D/dalvikvm(895): GC_FOR_ALLOC freed 143K, 4% free 5688K/5892K, paused 138ms, total 186ms
11-03 04:32:16.063: I/Choreographer(895): Skipped 91 frames!  The application may be doing too much work on its main thread.
11-03 04:32:16.603: I/Choreographer(895): Skipped 58 frames!  The application may be doing too much work on its main thread.
11-03 04:32:42.023: I/Choreographer(895): Skipped 46 frames!  The application may be doing too much work on its main thread.
11-03 04:32:44.223: I/Choreographer(895): Skipped 30 frames!  The application may be doing too much work on its main thread.
11-03 04:32:45.053: I/Choreographer(895): Skipped 122 frames!  The application may be doing too much work on its main thread.
11-03 04:32:45.513: I/Choreographer(895): Skipped 68 frames!  The application may be doing too much work on its main thread.
11-03 04:32:46.555: I/Choreographer(895): Skipped 135 frames!  The application may be doing too much work on its main thread.
11-03 04:32:49.742: D/dalvikvm(895): GC_FOR_ALLOC freed 152K, 4% free 6327K/6544K, paused 350ms, total 378ms
11-03 04:32:50.245: D/dalvikvm(895): GC_FOR_ALLOC freed 59K, 4% free 7253K/7540K, paused 187ms, total 190ms
11-03 04:32:50.349: I/Choreographer(895): Skipped 192 frames!  The application may be doing too much work on its main thread.
11-03 04:32:54.232: I/Choreographer(895): Skipped 35 frames!  The application may be doing too much work on its main thread.
11-03 04:32:54.702: I/Choreographer(895): Skipped 73 frames!  The application may be doing too much work on its main thread.
11-03 04:32:55.134: I/Choreographer(895): Skipped 71 frames!  The application may be doing too much work on its main thread.
11-03 04:32:55.968: I/Choreographer(895): Skipped 112 frames!  The application may be doing too much work on its main thread.
11-03 04:32:59.177: D/dalvikvm(895): GC_FOR_ALLOC freed 1715K, 21% free 6795K/8580K, paused 279ms, total 332ms
11-03 04:32:59.322: I/Choreographer(895): Skipped 134 frames!  The application may be doing too much work on its main thread.
11-03 04:33:03.003: I/Choreographer(895): Skipped 53 frames!  The application may be doing too much work on its main thread.
11-03 04:33:04.183: I/Choreographer(895): Skipped 35 frames!  The application may be doing too much work on its main thread.
11-03 04:33:04.643: I/Choreographer(895): Skipped 35 frames!  The application may be doing too much work on its main thread.
11-03 04:33:08.103: I/Choreographer(895): Skipped 43 frames!  The application may be doing too much work on its main thread.
11-03 04:34:58.453: D/AndroidRuntime(951): Shutting down VM
11-03 04:34:58.453: W/dalvikvm(951): threadid=1: thread exiting with uncaught exception (group=0x41465700)
11-03 04:34:58.464: E/AndroidRuntime(951): FATAL EXCEPTION: main
11-03 04:34:58.464: E/AndroidRuntime(951): java.lang.RuntimeException: Unable to instantiate application 安卓.app.Application: java.lang.IllegalStateException: Unable to get package info for com.yiqiexample.cabincrew; is package not installed?
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.LoadedApk.makeApplication(LoadedApk.java:509)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.ActivityThread.handleBindApplication(ActivityThread.java:4417)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.ActivityThread.access$1300(ActivityThread.java:141)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.os.Handler.dispatchMessage(Handler.java:99)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.os.Looper.loop(Looper.java:137)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.ActivityThread.main(ActivityThread.java:5103)
11-03 04:34:58.464: E/AndroidRuntime(951):  at java.lang.reflect.Method.invokeNative(Native Method)
11-03 04:34:58.464: E/AndroidRuntime(951):  at java.lang.reflect.Method.invoke(Method.java:525)
11-03 04:34:58.464: E/AndroidRuntime(951):  at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-03 04:34:58.464: E/AndroidRuntime(951):  at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-03 04:34:58.464: E/AndroidRuntime(951):  at dalvik.system.NativeStart.main(Native Method)
11-03 04:34:58.464: E/AndroidRuntime(951): Caused by: java.lang.IllegalStateException: Unable to get package info for com.yiqiexample.cabincrew; is package not installed?
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:369)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.LoadedApk.getClassLoader(LoadedApk.java:322)
11-03 04:34:58.464: E/AndroidRuntime(951):  at 安卓.app.LoadedApk.makeApplication(LoadedApk.java:501)
11-03 04:34:58.464: E/AndroidRuntime(951):  ... 11 more
11-03 04:35:10.544: D/dalvikvm(994): GC_FOR_ALLOC freed 55K, 5% free 2600K/2720K, paused 30ms, total 33ms
11-03 04:35:10.562: I/dalvikvm-heap(994): Grow heap (frag case) to 4.940MB for 2457616-byte allocation
11-03 04:35:10.673: D/dalvikvm(994): GC_FOR_ALLOC freed 2K, 3% free 4998K/5124K, paused 110ms, total 110ms
11-03 04:35:11.213: D/gralloc_goldfish(994): Emulator without GPU emulation detected.
11-03 04:40:44.032: D/AndroidRuntime(994): Shutting down VM
11-03 04:40:44.042: W/dalvikvm(994): threadid=1: thread exiting with uncaught exception (group=0x41465700)
11-03 04:40:44.112: E/AndroidRuntime(994): FATAL EXCEPTION: main
11-03 04:40:44.112: E/AndroidRuntime(994): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yiqiexample.cabincrew/com.yiqiexample.cabincrew.Food}: java.lang.NullPointerException
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.ActivityThread.access$600(ActivityThread.java:141)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.os.Handler.dispatchMessage(Handler.java:99)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.os.Looper.loop(Looper.java:137)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.ActivityThread.main(ActivityThread.java:5103)
11-03 04:40:44.112: E/AndroidRuntime(994):  at java.lang.reflect.Method.invokeNative(Native Method)
11-03 04:40:44.112: E/AndroidRuntime(994):  at java.lang.reflect.Method.invoke(Method.java:525)
11-03 04:40:44.112: E/AndroidRuntime(994):  at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-03 04:40:44.112: E/AndroidRuntime(994):  at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-03 04:40:44.112: E/AndroidRuntime(994):  at dalvik.system.NativeStart.main(Native Method)
11-03 04:40:44.112: E/AndroidRuntime(994): Caused by: java.lang.NullPointerException
11-03 04:40:44.112: E/AndroidRuntime(994):  at com.yiqiexample.cabincrew.Food.onCreate(Food.java:71)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.Activity.performCreate(Activity.java:5133)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 04:40:44.112: E/AndroidRuntime(994):  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-03 04:40:44.112: E/AndroidRuntime(994):  ... 11 more

如果您需要更多的编码来发现错误,请告诉我!:)


共 (1) 个答案

  1. # 1 楼答案

    假设第71行就是这个。-

    z.setOnClickListener(this);
    

    此行必须将z设置为空

    View z = findViewById(R.id.drinksbtn);
    

    仔细检查food布局是否包含id为drinksbtn且没有拼写错误的视图

    请注意,xml中没有drinksbtn,也没有foodbutton