恢复android应用程序时出现错误异常n

恢复android应用程序时出现错误异常n,android,Android,最近我买了一个Android应用程序。现在我正在重新设计和翻译它,并做一些小改动。 几分钟前,当我在后台关闭仍处于活动状态的应用程序时,我检测到一个错误,我打开另一个应用程序,然后继续我的应用程序。在这种情况下,应用程序崩溃,日志显示: 10-01 18:22:19.695: E/AndroidRuntime(23804): FATAL EXCEPTION: main 10-01 18:22:19.695: E/AndroidRuntime(23804): Process: com.comsat

最近我买了一个Android应用程序。现在我正在重新设计和翻译它,并做一些小改动。 几分钟前,当我在后台关闭仍处于活动状态的应用程序时,我检测到一个错误,我打开另一个应用程序,然后继续我的应用程序。在这种情况下,应用程序崩溃,日志显示:

10-01 18:22:19.695: E/AndroidRuntime(23804): FATAL EXCEPTION: main
10-01 18:22:19.695: E/AndroidRuntime(23804): Process: com.comsats.restaurantandroid, PID: 23804
10-01 18:22:19.695: E/AndroidRuntime(23804): **java.lang.RuntimeException: Unable to start activity ComponentInfo{com.comsats.restaurantandroid/com.comsats.restaurantandroid.activity.Home}: java.lang.IllegalArgumentException: n <= 0: 0**
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.ActivityThread.access$800(ActivityThread.java:142)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.os.Handler.dispatchMessage(Handler.java:102)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.os.Looper.loop(Looper.java:136)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.ActivityThread.main(ActivityThread.java:5118)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at java.lang.reflect.Method.invoke(Native Method)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
10-01 18:22:19.695: E/AndroidRuntime(23804): Caused by: java.lang.IllegalArgumentException: n <= 0: 0
10-01 18:22:19.695: E/AndroidRuntime(23804):    at java.util.Random.nextInt(Random.java:175)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at com.comsats.restaurantandroid.activity.Home.onCreate(Home.java:162)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.Activity.performCreate(Activity.java:5275)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-01 18:22:19.695: E/AndroidRuntime(23804):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
10-01 18:22:19.695: E/AndroidRuntime(23804):    ... 9 more
它只发生在家庭活动中,这是此活动的代码:

package com.comsats.restaurantandroid.activity;

import java.util.ArrayList;
import java.util.Random;

import com.comsats.restaurantandroid.Ad;
import com.comsats.restaurantandroid.Customer;
import com.comsats.restaurantandroid.MenuItemDetails;
import com.comsats.restaurantandroid.OrderDetail;
import com.comsats.restaurantandroid.R;
import com.comsats.restaurantandroid.TableNumbers;
import com.comsats.restaurantandroid.util.ImageLoader;
import com.comsats.restaurantandroid.util.URLConnectionReader;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;




public class Home extends ApplicationMenu {

    String[] classes = {"HotDishesList","CategoriesList","Order","Favourite","CallWaiter","Feedback"};
    protected TextView customFont;
    CountDownTimer countDownTimer;          // built in android class CountDownTimer
    long totalTimeCountInMilliseconds;      // total count down time in milliseconds
    long timeBlinkInMilliseconds;           // start time of start blinking
    boolean blink;                          // controls the blinking .. on

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (getIntent().getBooleanExtra("EXIT", false)) {
            finish();
        }
        super.onCreate(savedInstanceState);

        setContentView(R.layout.app_main);

        customFont=(TextView)findViewById(R.id.textView1);
        Typeface font = Typeface.createFromAsset(getAssets(), "font/OpenSans-Regular.ttf");
        customFont.setTypeface(font);
        customFont=(TextView)findViewById(R.id.footer);
        Typeface font2 = Typeface.createFromAsset(getAssets(), "font/OpenSans-Regular.ttf");
        customFont.setTypeface(font2);
        customFont=(TextView)findViewById(R.id.share);
        Typeface font3 = Typeface.createFromAsset(getAssets(), "font/OpenSans-Regular.ttf");
        customFont.setTypeface(font3);
        customFont=(TextView)findViewById(R.id.info);
        Typeface font4 = Typeface.createFromAsset(getAssets(), "font/OpenSans-Regular.ttf");
        customFont.setTypeface(font4);

        TextView contactBtn = (TextView) findViewById(R.id.info);
        RelativeLayout aboutBtn = (RelativeLayout) findViewById(R.id.aboutBtn);
        TextView share = (TextView) findViewById(R.id.share);


        contactBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
                Intent ourIntent = new Intent(Home.this, Contact.class);
                Home.this.startActivity(ourIntent);
            }
        });

        aboutBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
            finish();
                Intent ourIntent = new Intent(Home.this, About.class);
                Home.this.startActivity(ourIntent);
            }
        });

        share.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
            finish();
                Intent ourIntent = new Intent(Home.this, Social.class);
                Home.this.startActivity(ourIntent);
            }
        });


        ArrayList<MenuItemDetails> menu_details = GetMenuResults();
        final ListView lv1 = (ListView) findViewById(R.id.MenuList);
        lv1.setAdapter(new MenuListBaseAdapter(this, menu_details));

        lv1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                Object o = lv1.getItemAtPosition(position);
                MenuItemDetails obj_itemDetails = (MenuItemDetails)o;
                if(obj_itemDetails.getMenuItemID() == 4)
                {
                    doCall();
                }
                else if(obj_itemDetails.getMenuItemID() == 3)
                {
                    finish();
                    Intent ourIntent = new Intent(Home.this, Favourite.class);
                    Home.this.startActivity(ourIntent);
                }
                else
                {
                final String className = classes[obj_itemDetails.getMenuItemID()];
                Thread timer = new Thread()
                {
                    public void run(){
                            try{
                                Intent ourIntent = new Intent(Home.this, Loading.class);
                                Home.this.startActivity(ourIntent);
                                sleep(1000);

                            }catch (Exception e) {
                                // TODO: handle exception
                            }finally{
                                try {
                                    @SuppressWarnings("rawtypes")
                                    Class ourClass = Class.forName("com.comsats.restaurantandroid.activity." + className);
                                    finish();
                                    Intent ourIntent = new Intent(Home.this, ourClass);
                                    Home.this.startActivity(ourIntent);
                                } catch (ClassNotFoundException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                } 
                            }
                    }
                };

            timer.start();
                }
            }  
        });

        int size = Ad.list.size();
        //random index
        int index = new Random().nextInt(size);





    }

    private void doCall()
    {
        final AlertDialog.Builder alert = new AlertDialog.Builder(Home.this);

        alert.setTitle(this.getString(R.string.home_camarero));;
        LinearLayout layout = new LinearLayout(Home.this);
        layout.setOrientation(LinearLayout.VERTICAL);
        alert.setMessage(this.getString(R.string.home_mesa));

        //final EditText table = new EditText(Order.this);
        //table.setHint("Enter table no");


        final ArrayAdapter<String> adp = new ArrayAdapter<String>(Home.this,
                android.R.layout.simple_spinner_item, TableNumbers.tableNo);
        adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        final Spinner tableNo = new Spinner(Home.this);
        tableNo.setAdapter(adp);

        layout.addView(tableNo);

        alert.setView(layout);

        alert.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int whichButton) {
                        Thread timer = new Thread()
                        {
                            public void run(){
                                    try{
                                        sendCallToServer(String.valueOf(tableNo.getSelectedItem()), Customer.getUuid());
                                        Intent ourIntent = new Intent(Home.this, Loading.class);
                                        Home.this.startActivity(ourIntent);
                                        sleep(2000);

                                    }catch (Exception e) {
                                        // TODO: handle exception
                                    }finally{
                                        finish();
                                        Intent ourIntent = new Intent(Home.this, Home.class);
                                        Home.this.startActivity(ourIntent);
                                    }
                            }
                        };

                    timer.start();
                    Context c = Home.this;

                        Toast.makeText(c,
                                c.getResources().getString(R.string.calledwaiter),
                                Toast.LENGTH_SHORT).show();
                            }   


                });

        alert.setNegativeButton(R.string.cancel,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int whichButton) {
                        // Canceled.
                        dialog.cancel();
                    }
                });

        alert.show();
    }

    private String sendCallToServer(String tableNo, String customerID)
    {
        String content = null;
        try {

            content = URLConnectionReader.getText(URLConnectionReader.getIP()
                    + "do_call_waiter.jsp?tableNo="+tableNo+"&customerID="+customerID);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return content;

    }


    private ArrayList<MenuItemDetails> GetMenuResults(){
        ArrayList<MenuItemDetails> results = new ArrayList<MenuItemDetails>();

        MenuItemDetails item_details0 = new MenuItemDetails();
        MenuItemDetails item_details1 = new MenuItemDetails();
        MenuItemDetails item_details2 = new MenuItemDetails();
        MenuItemDetails item_details3 = new MenuItemDetails();
        MenuItemDetails item_details4 = new MenuItemDetails();
        MenuItemDetails item_details5 = new MenuItemDetails();


        item_details0.setMenuItemID(0);
        item_details0.setMenuItemName(this.getString(R.string.home_especialidades));
        results.add(item_details0);
        item_details1.setMenuItemID(1);
            item_details1.setMenuItemName(this.getString(R.string.home_menu));
            results.add(item_details1);
            item_details2.setMenuItemID(2);
            item_details2.setMenuItemName(this.getString(R.string.home_pedidos));
            results.add(item_details2);
            item_details3.setMenuItemID(3);
            item_details3.setMenuItemName(this.getString(R.string.home_favoritos));
            results.add(item_details3);
            item_details4.setMenuItemID(4);
            item_details4.setMenuItemName(this.getString(R.string.home_camarero));
            results.add(item_details4);
            item_details5.setMenuItemID(5);
            item_details5.setMenuItemName(this.getString(R.string.home_comentarios));
            results.add(item_details5);


        return results;
    }
    public void onBackPressed() {
        finish();
    }

}
我一直在寻找一些信息,我发现这是由于一个变量的值在简历上是无效的,但我不知道如何检测到底是什么。你能帮我吗


提前感谢

看起来您的Ad.list.size返回0。这可能会有帮助:Yes daentech!非常感谢你!这一行是插入广告的代码的剩余部分,我已经删除了它,因为我不想要它。这里的代码太多了。修剪不必要的东西: