按钮点击崩溃的Android应用意图

时间:2014-05-11 20:44:43

标签: android eclipse android-intent

我的应用程序(android)工作正常,直到我点击一个名为chooseDistance的按钮,它然后给出错误消息说应用程序已停止,一旦我选择确定它再次启动应用程序并保存先前的变量。我正在使用Galaxy S5以便运行我的应用程序我必须将我的.apk上传到谷歌驱动器并将其安装到我的手机上,因此我没有提供的logcat信息。这是我的代码:

package com.example.drivetext;

import java.util.ArrayList;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class setdestination extends Activity implements OnMapLongClickListener {

        private GoogleMap map;          
        Location myLocation;
        TextView tvLocInfo;
        LatLng pointfinal;
        ListView listview;
        ArrayList<String> distancesendList;
        String finaldistance;
        String contactNo;
        String message;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.setdestination);
            Intent intent = getIntent();
            contactNo = intent.getStringExtra("PhoneNumber");
            message = intent.getStringExtra("TextMessage");
            Toast.makeText(this, contactNo, Toast.LENGTH_LONG).show();
            Toast.makeText(this, message, Toast.LENGTH_LONG).show();                

            ListView distanceList=(ListView)findViewById(R.id.list);


            distancesendList = new ArrayList<String>();
            getdistances();
            // Create The Adapter with passing ArrayList as 3rd parameter
            ArrayAdapter<String> arrayAdapter =      
            new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, distancesendList);
            // Set The Adapter
            distanceList.setAdapter(arrayAdapter); 

            // register onClickListener to handle click events on each item
            distanceList.setOnItemClickListener(new OnItemClickListener()
               {
                        // argument position gives the index of item which is clicked
                       public void onItemClick(AdapterView<?> arg0, View v,int position, long arg3)
                       {

                               String selecteddistance=distancesendList.get(position);
                               finaldistance = selecteddistance;
                               Toast.makeText(getApplicationContext(), "Distance Selected : "+selecteddistance,   Toast.LENGTH_LONG).show();
                            }
               });

            tvLocInfo = (TextView)findViewById(R.id.locinfo);

            FragmentManager myFragmentManager = getFragmentManager();
            MapFragment myMapFragment = (MapFragment)myFragmentManager.findFragmentById(R.id.map);
            map = myMapFragment.getMap();

            map.setMyLocationEnabled(true);

            map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            //myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            //myMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            //myMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
            map.setOnMapLongClickListener(this);

            Button chooseDistance = (Button) findViewById(R.id.btnchooseDistance);
              chooseDistance.setOnClickListener(new View.OnClickListener() {              
                 public void onClick(View arg0) {                        
                     Intent intent3 = new Intent(getApplicationContext(), targetdistance.class);
                     intent3.putExtra("PhoneNumber", contactNo);
                     intent3.putExtra("TextMessage", message);
                     intent3.putExtra("Coordinate", pointfinal);
                     intent3.putExtra("SelectedDistance", finaldistance);
                     startActivity(intent3);
                     }
              });
        }

        void getdistances()
        {
            distancesendList.add("100");
            distancesendList.add("250");
            distancesendList.add("500");
            distancesendList.add("1000");
        }

        public void onMapLongClick(LatLng point) {
            tvLocInfo.setText("New marker added@" + point.toString());
            map.addMarker(new MarkerOptions().position(point).title(point.toString()));
            pointfinal = point;
            Toast.makeText(this, point.toString(), Toast.LENGTH_LONG).show();
        }
   }

0 个答案:

没有答案