从MapView拨打电话

时间:2013-02-04 16:37:15

标签: android android-mapview itemizedoverlay phone-call

当我点击alertDialog按钮时,我正在尝试拨打电话,此警报对话连接到每个地理位置的地图视图。我想我在这里做错了什么 这是我的logcat:

02-04 16:21:22.578: E/AndroidRuntime(432): FATAL EXCEPTION: main
02-04 16:21:22.578: E/AndroidRuntime(432): java.lang.NullPointerException
02-04 16:21:22.578: E/AndroidRuntime(432):  at fsg.mpssri.MEGAMAG.ListItimizedOverlay$CallMeclass.access$0(ListItimizedOverlay.java:88)
02-04 16:21:22.578: E/AndroidRuntime(432):  at fsg.mpssri.MEGAMAG.ListItimizedOverlay$1.onClick(ListItimizedOverlay.java:66)
02-04 16:21:22.578: E/AndroidRuntime(432):  at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
02-04 16:21:22.578: E/AndroidRuntime(432):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 16:21:22.578: E/AndroidRuntime(432):  at android.os.Looper.loop(Looper.java:130)
02-04 16:21:22.578: E/AndroidRuntime(432):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-04 16:21:22.578: E/AndroidRuntime(432):  at java.lang.reflect.Method.invokeNative(Native Method)
02-04 16:21:22.578: E/AndroidRuntime(432):  at java.lang.reflect.Method.invoke(Method.java:507)
02-04 16:21:22.578: E/AndroidRuntime(432):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-04 16:21:22.578: E/AndroidRuntime(432):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-04 16:21:22.578: E/AndroidRuntime(432):  at dalvik.system.NativeStart.main(Native Method)

这里是我的ListItimizedOverlay类的代码

package fsg.mpssri.MEGAMAG;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class ListItimizedOverlay extends ItemizedOverlay<OverlayItem> {

    public CallMeclass clme;
    public String phoneNum = "55-223-014";
    public GeoloMe geololome; 
    private Context context;
    private ArrayList<OverlayItem> arrayListOverlayItem = new ArrayList<OverlayItem>();
    public ListItimizedOverlay(Drawable defaultMarker) {
        // TODO Auto-generated constructor stub

        super(boundCenterBottom(defaultMarker));
    }

    public ListItimizedOverlay(Drawable defaultMarker, Context pContext) 
    {
      super(boundCenterBottom(defaultMarker));
      this.context = pContext;
    }

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return arrayListOverlayItem.get(i);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return arrayListOverlayItem.size();
    }

    @Override
    protected boolean onTap(int index) {
        // TODO Auto-generated method stub
        OverlayItem item = arrayListOverlayItem.get(index);
          AlertDialog.Builder dialog = new AlertDialog.Builder(context);
          dialog.setIcon(R.drawable.icon__telephone);
          dialog.setTitle(item.getTitle());
          dialog.setMessage(item.getSnippet());
           //phoneNum = item.getSnippet();
          dialog.setPositiveButton("call us", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                //geololome.makeUrcall(phoneNum);
                Toast.makeText(context, "azerty", Toast.LENGTH_SHORT);

              clme.goCallMe(phoneNum);


            }


        });
          dialog.show();
          return true;
    }

    public void addOverlayItem(OverlayItem overlay) 
    {
        arrayListOverlayItem.add(overlay);
        populate();
    }




private class CallMeclass extends Activity{

    private void goCallMe(String phonenumber ) {
        // TODO Auto-generated method stub
        Intent i = new
                Intent(android.content.Intent.ACTION_CALL,
                        Uri.parse(phonenumber));
        startActivity(i);
    }
}

}

希望你能帮助我的朋友们 感谢

1 个答案:

答案 0 :(得分:0)

您没有在任何地方实例化clme。这就是你获得NPE的原因。

在调用方法之前先执行clme = new CallMeclass();

您不需要此处的CallMeclass。您可以直接从点击处理程序中激活意图。