Java 带有谷歌地图标记的marge滑动按钮

Java 带有谷歌地图标记的marge滑动按钮,java,android,google-maps,button,swipe,Java,Android,Google Maps,Button,Swipe,我有一个带有标记的谷歌地图,我想把它和ebanx进行集成 /滑动按钮,但当我尝试滑动按钮时,会出现以下错误 java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“void com.ebanx.swipebtn.SwipeButton.setOnStateChangeListener(com.ebanx.swipebtn.OnStateChangeListener)” 下面是我的密码 MapsActivity.java public class MapsAct

我有一个带有标记的谷歌地图,我想把它和ebanx进行集成 /滑动按钮,但当我尝试滑动按钮时,会出现以下错误

java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“void com.ebanx.swipebtn.SwipeButton.setOnStateChangeListener(com.ebanx.swipebtn.OnStateChangeListener)”

下面是我的密码 MapsActivity.java

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private List<LocationModel> mListMarker = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        getAllDataLocationLatLng();

        swipe(); // I call it from here

    }

    
    private void getAllDataLocationLatLng(){
        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage("Menampilkan data marker ..");
        dialog.show();

        ApiService apiService = ApiClient.getClient().create(ApiService.class);
        Call<ListLocationModel> call = apiService.getAllLocation();
        call.enqueue(new Callback<ListLocationModel>() {
            @Override
            public void onResponse(Call<ListLocationModel> call, Response<ListLocationModel> response) {
                dialog.dismiss();
                mListMarker = response.body().getmData();
                initMarker(mListMarker);
            }

            @Override
            public void onFailure(Call<ListLocationModel> call, Throwable t) {
                dialog.dismiss();
                Toast.makeText(MapsActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });

    }
    private void initMarker(List<LocationModel> listData){
         
        for (int i=0; i<mListMarker.size(); i++){
             
            LatLng location = new LatLng(Double.parseDouble(mListMarker.get(i).getLatutide()), Double.parseDouble(mListMarker.get(i).getLongitude()));
            
            mMap.addMarker(new MarkerOptions().position(location).title(mListMarker.get(i).getImageLocationName()));
            
            LatLng latLng = new LatLng(Double.parseDouble(mListMarker.get(0).getLatutide()), Double.parseDouble(mListMarker.get(0).getLongitude()));
            
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latLng.latitude,latLng.longitude), 11.0f));
        }
       

    }
//ebanx /swipe-button code
    private void swipe(){

        SwipeButton swipeButton = (SwipeButton)findViewById(R.id.swipe_button);
        swipeButton.setOnStateChangeListener(new OnStateChangeListener() {
            @Override
            public void onStateChange(boolean active) {
                /*
                More code here*/
            }
        });
    }
}
公共类MapsActivity扩展了FragmentActivity在MapreadyCallback上的实现{
私有谷歌地图;
私有列表mListMarker=new ArrayList();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
}
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
mMap=谷歌地图;
getAllDataLocationLatLng();
swipe();//我从这里调用它
}
私有void getAllDataLocationLatLng(){
最终进度对话框=新建进度对话框(本);
setMessage(“Menampilkan数据标记…”);
dialog.show();
ApiService ApiService=ApiClient.getClient().create(ApiService.class);
Call Call=apiService.getAllLocation();
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
dialog.dismise();
mListMarker=response.body().getmData();
initMarker(mListMarker);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
dialog.dismise();
Toast.makeText(MapsActivity.this,t.getMessage(),Toast.LENGTH_SHORT.show();
}
});
}
私有void initMarker(列表数据){

对于(int i=0;我不太明白您在这里想要实现什么,但请将您的
findViewById(R.id.swipe_按钮)
移动到
onCreate()
方法,并在活动中声明
swipeButton
,以便您可以在滑动()上访问它 method@javdromero我已经插入了一个图像来详细说明我的实现。在您的xml中,您的SwipeButton需要一个id,在本例中,您指的是R.id.swipe_button@javdromero我不知道我怎么会错过“`android:id=“@+id/swipe_button”``但事实上,我做到了你告诉我的一切,而且确实奏效了!谢谢
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />

    <com.ebanx.swipebtn.SwipeButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="18sp"
        android:layout_alignParentBottom="true"
        app:inner_text_background="@drawable/inner_text_shape"
        app:button_image_disabled="@drawable/ic_lock_open_black_24dp"
        app:button_image_enabled="@drawable/ic_lock_outline_black_24dp"
        app:button_background="@drawable/shape_button2"
        app:inner_text="Swipe to Unlock"
        app:inner_text_size="20sp"
        app:inner_text_bottom_padding="15dp"
        app:inner_text_top_padding="15dp"
        app:button_top_padding="15dp"
        app:button_right_padding="15dp"
        app:button_bottom_padding="15dp"
        app:button_left_padding="15dp"
        />



</RelativeLayout>