Question

i'm trying to make a phone call when i click on alertDialog button,this alertdialog attached to a mapview at every geopoint. I think i'm doing something wrong here this is my 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)

and here my code for the class of 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);
    }
}

}

Hope you can help me my friends thanks

Was it helpful?

Solution

You are not instantiating clme anywhere. That's why you get the NPE.

Do clme = new CallMeclass(); first before calling the method.

You don't need the CallMeclass here. You can directly fire the intent from your click handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top