1

我是安卓新手。我的问题是当我尝试单击主类(Trip_planning_list)中的按钮时,我需要在我的子类(EventListAdapter)中启用一个图像视图,然后我收到以下 logcat 错误和我的代码。

谢谢,赛姆。

05-23 18:12:37.292: I/value of imagerotation(606): [mmm]
05-23 18:12:39.052: D/AndroidRuntime(606): Shutting down VM
05-23 18:12:39.052: W/dalvikvm(606): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-23 18:12:39.082: E/AndroidRuntime(606): FATAL EXCEPTION: main
05-23 18:12:39.082: E/AndroidRuntime(606): java.lang.NullPointerException
05-23 18:12:39.082: E/AndroidRuntime(606):  at com.igfa.Trip_planning_list$3.onClick(Trip_planning_list.java:106)
05-23 18:12:39.082: E/AndroidRuntime(606):  at android.view.View.performClick(View.java:2408)
05-23 18:12:39.082: E/AndroidRuntime(606):  at android.view.View$PerformClick.run(View.java:8816)
05-23 18:12:39.082: E/AndroidRuntime(606):  at android.os.Handler.handleCallback(Handler.java:587)
05-23 18:12:39.082: E/AndroidRuntime(606):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-23 18:12:39.082: E/AndroidRuntime(606):  at android.os.Looper.loop(Looper.java:123)
05-23 18:12:39.082: E/AndroidRuntime(606):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-23 18:12:39.082: E/AndroidRuntime(606):  at java.lang.reflect.Method.invokeNative(Native Method)
05-23 18:12:39.082: E/AndroidRuntime(606):  at java.lang.reflect.Method.invoke(Method.java:521)
05-23 18:12:39.082: E/AndroidRuntime(606):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-23 18:12:39.082: E/AndroidRuntime(606):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-23 18:12:39.082: E/AndroidRuntime(606):  at dalvik.system.NativeStart.main(Native Method)


package com.igfa;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Dialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.net.Uri;
import android.opengl.Visibility;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.igfa.database.DBAdapter;
public class Trip_planning_list extends ListActivity {
    ImageView facebookimage,donateimage,getthemobileapp;
    Timer timer;
    TimerTask task;
    ImageView slidingimage,deleteCrossButton,deleteBigButton;
    int value1=0;

    public int currentimageindex=0;
    boolean f1=false;
    private int[] IMAGE_IDS = {
            R.drawable.facebook,
            R.drawable.donateimage,
            R.drawable.getthemobileapp
    };
    TextView name,address,dob,dep,mstatus;
    ListView lv;
    DBAdapter db;
    /** Called when the activity is first created. */
    Button cancel,ok;
    TextView addView,add_list;
    ImageButton backButton,EditButton;
    EditText edit;  
    Cursor state_value;
    RelativeLayout _tmplinear;
    ArrayList<String>value=new ArrayList<String>();
    int i=1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tripplanninglist);

        db= new DBAdapter(getApplicationContext());
        db.open();
         facebookimage=(ImageView)findViewById(R.id.facebook);

         final Handler mHandler = new Handler();

            // Create runnable for posting
            final Runnable mUpdateResults = new Runnable() {
                public void run() {

                    AnimateandSlideShow();

                }
            };

            int delay = 1000; // delay for 1 sec.

            int period = 8000; // repeat every 4 sec.

            Timer timer = new Timer();
            timer.scheduleAtFixedRate(new TimerTask() {

                public void run() {

                    mHandler.post(mUpdateResults);

                }

            }, delay, period);




        addView =(TextView)findViewById(R.id.Add);
        backButton = (ImageButton)findViewById(R.id.ig);
        EditButton = (ImageButton)findViewById(R.id.edit_button);

        EditButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                deleteCrossButton.setVisibility(View.VISIBLE);
            }
        });


        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent backIntent = new Intent(Trip_planning_list.this,Igfamobile1Activity.class);
                startActivity(backIntent);
            }
        });


        try {

            state_value= db.getState();

            if (   state_value.moveToFirst())
            {
                do {    
                    value.add(state_value.getString(1));

                }

                while (state_value.moveToNext());
            }

        } catch (SQLException e) {
            // TODO Auto-g


        }

        Collections.sort(value);
        lv = (ListView) findViewById(R.id.list);
        lv=getListView();
        lv.setAdapter(new StateListAdapter(this));
        lv.setFastScrollEnabled(true);


        ListAdapter listAdapter = lv.getAdapter();
        if (listAdapter == null) {
            // pre-condition
            return;
        }
        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, lv);
            //listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = lv.getLayoutParams();
        params.height = totalHeight
                + (lv.getDividerHeight() * (listAdapter.getCount() - 1));
        lv.setLayoutParams(params);
        lv.requestLayout();

        addView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                final Dialog dialog = new Dialog(Trip_planning_list.this);
                dialog.setContentView(R.layout.custom1);
                dialog.setCancelable(true);
                cancel=(Button)dialog.findViewById(R.id.Cancle_c);
                ok=(Button)dialog.findViewById(R.id.OK_c);
                edit=(EditText)dialog.findViewById(R.id.edit_c);
                ok.setOnClickListener(new OnClickListener() {
                    int i=0;
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        //value.clear();
                        ok.setBackgroundResource(R.drawable.ok);
                        cancel.setBackgroundResource(R.drawable.cancel_hover);

                        value.add(edit.getText().toString().trim());
                        db.insertStateName(edit.getText().toString().trim());
                        Log.i("value of addtrip",value.get(i));
                        i++;
                        edit.setText("");


                        Collections.sort(value);

                        lv=getListView();
                        lv.setAdapter(new EventListAdapter(this));

                        lv.setFastScrollEnabled(true);
                        dialog.dismiss();
                    }
                });
                cancel.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ok.setBackgroundResource(R.drawable.ok_hover);
                        cancel.setBackgroundResource(R.drawable.cancel1);
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
                dialog.show();

            }

        });


    }


    public void onClick(View v) {

        finish();
        android.os.Process.killProcess(android.os.Process.myPid());
    }

    private void AnimateandSlideShow() {

        slidingimage = (ImageView)findViewById(R.id.facebook);
        slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);

        currentimageindex++;
        value1=currentimageindex;
        facebookimage.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(value1%3==1)
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);   
                    i.setData(Uri.parse("http://www.facebook.com/pages/International-Game-Fish-Association/103760506329326"));   
                    startActivity(i);  
                }
                else if(value1%3==2)
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);   
                    i.setData(Uri.parse("http://www.igfa.org/Donate/DonorSocieties.aspx"));   
                    startActivity(i);  
                }else
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);   
                    i.setData(Uri.parse("http://www.igfa.org/Fish/IGFA-Mobile.aspx"));   
                    startActivity(i); 
                }
            }
        });
        Log.v("---==================", ""+currentimageindex);
        Log.i("value of imagerotation",String.valueOf(value));
        //Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);

        //slidingimage.startAnimation(rotateimage);

    }

    /*
     * Adapter for populating data in list
     */
    private class EventListAdapter extends BaseAdapter {


        private OnClickListener mContext;


        public EventListAdapter(OnClickListener onClickListener) {
            mContext = onClickListener;
        }

        public int getCount() {

            return value.size();
        }
        public Object getItem(int position1) {
            return position1;
        }
        public long getItemId(int position1) {
            return position1;
        }
        public View getView(final int position1, View convertView, ViewGroup parent) {

            View v;
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.trip_list, null);

            deleteCrossButton = (ImageView)findViewById(R.id.delete_cross_icon);
            deleteBigButton = (ImageView)findViewById(R.id.deleteBtn);


            add_list=(TextView)v.findViewById(R.id.Add_trip);
            add_list.setText(value.get(position1));
            _tmplinear=(RelativeLayout)v.findViewById(R.id.linear_trip);


            deleteCrossButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    deleteBigButton.setVisibility(View.VISIBLE);
                }
            });


            _tmplinear.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent in=new Intent(getApplicationContext(),TripPlaning_SubList.class);
                    in.putExtra("select", value.get(position1));
                    startActivity(in);
                }
            });                     


            return v;

        }

    };
    /*
     * Adapter for populating data in list
     */
    private class StateListAdapter extends BaseAdapter {


        private Trip_planning_list mContext;


        public StateListAdapter(Trip_planning_list tripPlanningList) {
            mContext = tripPlanningList;
        }

        public int getCount() {

            return value.size();
        }
        public Object getItem(int position) {
            return position;
        }
        public long getItemId(int position) {
            return position;
        }
        public View getView(final int position, View convertView, ViewGroup parent) {

            View v;
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.trip_list, null);

            add_list=(TextView)v.findViewById(R.id.Add_trip);

            add_list.setText(value.get(position));

            _tmplinear=(RelativeLayout)v.findViewById(R.id.linear_trip);

            _tmplinear.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent in=new Intent(getApplicationContext(),TripPlaning_SubList.class);
                    in.putExtra("select", value.get(position));
                    startActivity(in);
                }
            });    



            return v;



        }

    };

}
4

0 回答 0