Android上的谷歌地图图标图像

时间:2015-04-13 21:30:04

标签: android image google-maps android-intent

我正在开发一个应用程序,显示谷歌地图和用户创建的一些标记。

此标记由外部数据库填充,并通过webservice进行连接。

我将来自此URL的MarkerOptions()。中的url图像放入。此图像可以从所有标记中正确显示。但我对setOnInfoWindowClickListener也有一个意图,如果我显示这个图标图像,意图不起作用。如果我从图标图像中删除鳕鱼,意图正常工作。

有人可以帮助我吗?

代码

public void onResume() {
    super.onResume();

    dao = new LocalizacoesDAO(context);
    ArrayList<Localizacoes> lista = dao.buscarLocalizacoes();
    if (lista.size() > 1) {
        for (int i = 0; i < lista.size(); i++) {
            URL url = null;
            try {
                url = new URL(""+lista.get(i).getImagem()+"");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            Bitmap bmp = null;
            try {
                bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
            Bitmap bmpok = Bitmap.createScaledBitmap(bmp, 30, 30, false);

            googlemap.addMarker(new MarkerOptions()
                        .title(lista.get(i).getNome() + " " + lista.get(i).getDescricao())
                        .snippet(String.valueOf(lista.get(i).getId()))
                        .position(lista.get(i).getLatLng())
                        .icon(BitmapDescriptorFactory.fromBitmap(bmpok)));

            }
        }
    }

 googlemap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {


            Intent intent = new Intent(MainActivity.this,infoActivity.class);
            String title = marker.getTitle().toString();
            String snippet = marker.getSnippet();

            intent.putExtra("nome", title);
            intent.putExtra("id", snippet);
            startActivity(intent);


        }
    });
}

ERROR

04-13 18:28:07.624    5453-5453/com.partytime.myapplication W/System.err﹕ java.net.SocketException: sendto failed: EPIPE (Broken pipe)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.io.IoBridge.sendto(IoBridge.java:475)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at java.net.PlainSocketImpl.write(PlainSocketImpl.java:508)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:270)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.net.http.FixedLengthOutputStream.flush(FixedLengthOutputStream.java:49)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:188)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
04-13 18:28:07.634    5453-5453/com.partytime.myapplication W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at com.partytime.myapplication.LocalizacoesDAO.buscarIdLocalizacoes(LocalizacoesDAO.java:191)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at com.partytime.myapplication.infoActivity.onCreate(infoActivity.java:36)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5184)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.ActivityThread.access$700(ActivityThread.java:143)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 18:28:07.644    5453-5453/com.partytime.myapplication W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4963)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
04-13 18:28:07.654    5453-5453/com.partytime.myapplication W/System.err﹕ Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
04-13 18:28:07.664    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.io.Posix.sendtoBytes(Native Method)
04-13 18:28:07.664    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.io.Posix.sendto(Posix.java:146)
04-13 18:28:07.664    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
04-13 18:28:07.664    5453-5453/com.partytime.myapplication W/System.err﹕ at libcore.io.IoBridge.sendto(IoBridge.java:473)
04-13 18:28:07.674    5453-5453/com.partytime.myapplication W/System.err﹕ ... 25 more
04-13 18:28:07.674    5453-5453/com.partytime.myapplication D/AndroidRuntime﹕ Shutting down VM
04-13 18:28:07.674    5453-5453/com.partytime.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41ed6438)
04-13 18:28:07.684    5453-5453/com.partytime.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.partytime.myapplication/com.partytime.myapplication.infoActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
            at android.app.ActivityThread.access$700(ActivityThread.java:143)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4963)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.partytime.myapplication.infoActivity.onCreate(infoActivity.java:37)
            at android.app.Activity.performCreate(Activity.java:5184)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
            at android.app.ActivityThread.access$700(ActivityThread.java:143)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4963)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

所以,错误说:

     Caused by: java.lang.NullPointerException
        at com.partytime.myapplication.infoActivity.onCreate(infoActivity.java:37)

所以它应该与infoActivity

相关

可能的原因之一是您传递的字符串为null,而infoActivity正在获取字符串并尝试访问该值。

Intent intent = new Intent(MainActivity.this,infoActivity.class);
intent.putExtra("nome", title);
intent.putExtra("id", snippet);

如果这是原因,您可以检查infoActivity中的字符串。

Intent intent= getIntent();
String title = intent.getExtra("nome");
String id = = intent.getExtra("id");

if (id == null || title == null) 
   // Exception