-1

当我单击警报对话框按钮时,我正在尝试拨打电话,此警报对话框附加到每个地理点的地图视图。我想我在这里做错了这是我的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);
    }
}

}

希望朋友们能帮帮我 谢谢

4

1 回答 1

0

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

clme = new CallMeclass();调用方法之前先做。

这里不需要 CallMeclass。您可以直接从您的点击处理程序触发意图。

于 2013-02-04T16:42:52.857 回答