S
S
Suguru_Evillione2022-04-03 20:02:29
Java
Suguru_Evillione, 2022-04-03 20:02:29

Why can't a variable be converted to an integer?

For some reason it throws an error
'startStories()' in 'jp.shts.android.storiesprogressview.StoriesProgressView' cannot be applied to '(int)'
Even though the "counter" variable is initially set to int. Or I do not understand something?

public class StoryViewActivity extends AppCompatActivity implements StoriesProgressView.StoriesListener {

    int counter = 0;
    long pressTime = 0L;
    final long limit = 500L;

        ConstraintLayout message = findViewById(R.id.message);

        if (userid.equals(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid())){
            r_seen.setVisibility(View.VISIBLE);
            story_delete.setVisibility(View.VISIBLE);
            message.setVisibility(View.GONE);
        }
        r_seen.setOnClickListener(v -> {
            Intent intent = new Intent(StoryViewActivity.this, ViewedActivity.class);
            intent.putExtra("id",userid);
            intent.putExtra("storyid",storyids.get(counter));
            startActivity(intent);
        });

        story_delete.setOnClickListener(v -> {
            DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Story")
                    .child(userid).child(storyids.get(counter));
            reference.removeValue();
        });

        reverse.setOnClickListener(v -> storiesProgressView.reverse());
        reverse.setOnTouchListener(onTouchListener);

        skip.setOnClickListener(v -> storiesProgressView.skip());
        skip.setOnTouchListener(onTouchListener);

        requestQueue = Volley.newRequestQueue(getApplicationContext());

        sendMessage = findViewById(R.id.sendMessage);
        imageView2 = findViewById(R.id.imageView2);
        imageView2.setOnClickListener(v -> {
            String msg = sendMessage.getText().toString();
            if (msg.isEmpty()){
                new StyleableToast
                        .Builder(getApplicationContext())
                        .text("Type something")
                        .textColor(Color.WHITE)
                        .gravity(0)
                        .textBold()
                        .length(2000)
                        .solidBackground()
                        .backgroundColor(getResources().getColor(R.color.colorPrimary))
                        .show();
            }else {
                notify = true;
                DatabaseReference databaseReference1 = FirebaseDatabase.getInstance().getReference();
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("sender", Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid());
                hashMap.put("receiver", userid);
                hashMap.put("msg", msg);
                hashMap.put("isSeen", false);
                hashMap.put("timeStamp", images.get(counter));
                hashMap.put("type", "story");
                databaseReference1.child("Chats").push().setValue(hashMap);

                final DatabaseReference chatRef1 = FirebaseDatabase.getInstance().getReference("Chatlist")
                        .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                        .child(userid);
                chatRef1.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        if (!snapshot.exists()){
                            chatRef1.child("id").setValue(userid);
                        }
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {
                        new StyleableToast
                                .Builder(getApplicationContext())
                                .text(error.getMessage())
                                .textColor(Color.WHITE)
                                .textBold()
                                .length(2000)
                                .gravity(0)
                                .solidBackground()
                                .backgroundColor(getResources().getColor(R.color.colorPrimary))
                                .show();
                    }
                });

                final DatabaseReference chatRef2 = FirebaseDatabase.getInstance().getReference("Chatlist")
                        .child(userid)
                        .child(FirebaseAuth.getInstance().getCurrentUser().getUid());

                chatRef2.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        if (!snapshot.exists()){
                            chatRef2.child("id").setValue(FirebaseAuth.getInstance().getCurrentUser().getUid());
                        }
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {
                        new StyleableToast
                                .Builder(getApplicationContext())
                                .text(error.getMessage())
                                .textColor(Color.WHITE)
                                .gravity(0)
                                .textBold()
                                .length(2000)
                                .solidBackground()
                                .backgroundColor(getResources().getColor(R.color.colorPrimary))
                                .show();
                    }
                });

                new StyleableToast
                        .Builder(getApplicationContext())
                        .text("Message sent")
                        .textColor(Color.WHITE)
                        .textBold()
                        .length(2000)
                        .solidBackground()
                        .gravity(0)
                        .backgroundColor(getResources().getColor(R.color.colorPrimary))
                        .show();

                DatabaseReference dataRef = FirebaseDatabase.getInstance().getReference("Users").child(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid());
                dataRef.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        ModelUser user = dataSnapshot.getValue(ModelUser.class);
                        if (notify){
                            sendNotification(userid, Objects.requireNonNull(user).getName(), "Sent a message");

                        }
                        notify = false;
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {

                    }
                });
            }
        });

        sendMessage.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                storiesProgressView.pause();


            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });


    }

    @Override
    public void onNext() {
        Glide.with(getApplicationContext()).load(images.get(++counter)).into(imageView);
        addView(storyids.get(counter));
        seenNumber(storyids.get(counter));
    }

    @Override
    public void onPrev() {
        if ((counter - 1) < 0) return;
        Glide.with(getApplicationContext()).load(images.get(--counter)).into(imageView);
        seenNumber(storyids.get(counter));
    }


    private void getStories(String userid){
        images = new ArrayList<>();

        storyids = new ArrayList<>();
        DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Story")
                .child(userid);
        reference.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                images.clear();
                storyids.clear();
                for (DataSnapshot snapshot1 : snapshot.getChildren()){
                    ModelStory modelStory = snapshot1.getValue(ModelStory.class);
                    long timecurrent = System.currentTimeMillis();
                    if (timecurrent > Objects.requireNonNull(modelStory).getTimestart() && timecurrent < modelStory.getTimeend()){
                        images.add(modelStory.imageUri);

                        storyids.add(modelStory.storyid);
                    }
                }
                storiesProgressView.setStoriesCount(images.size());
                storiesProgressView.setStoryDuration(5000L);
                storiesProgressView.setStoriesListener(StoryViewActivity.this);
                storiesProgressView.startStories(counter);
                Glide.with(getApplicationContext()).load(images.get(counter)).into(imageView);
                addView(storyids.get(counter));
                seenNumber(storyids.get(counter));
            }


Separate line with an error:
storiesProgressView.startStories(counter);

Part of the code had to be removed due to restrictions

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2022-04-03
@Suguru_Evillione

'startStories()' in 'jp.shts.android.storiesprogressview.StoriesProgressView' cannot be applied to '(int)'

The startStories() method cannot be applied to (int).
Those. the method does not accept anything, and you passed a variable to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question