0
            Класс адаптер:
            package com.example.personalaccounting;
            
            import android.content.Context;
            import android.os.Build;
            import android.view.LayoutInflater;
            import android.view.View;
            import android.view.ViewGroup;
            import android.widget.TextView;
            
            import androidx.annotation.RequiresApi;
            import androidx.recyclerview.widget.RecyclerView;
            
            import java.util.List;
            
            public class CountingEntry_Adapter extends RecyclerView.Adapter<CountingEntry_Adapter.ViewHolder>
            {
            
                private final LayoutInflater inflater;
                private final List<CountingEntry> Entries;
            
                public CountingEntry_Adapter(Context context, List<CountingEntry> Entries_)
                {
                    this.Entries = Entries_;
                    this.inflater = LayoutInflater.from(context);
                }
                @RequiresApi(api = Build.VERSION_CODES.O)
                @Override
                public CountingEntry_Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
                {
                    View view = inflater.inflate(R.layout.list_item, parent, false);
                    return new ViewHolder(view);
                }
            
                @RequiresApi(api = Build.VERSION_CODES.O)
                @Override
                public void onBindViewHolder(CountingEntry_Adapter.ViewHolder holder, int position)
                {
                    CountingEntry Entry = Entries.get(position);
                    holder.purchase.setText(Entry.GetPurchase());
                    holder.cost.setText(Entry.GetCost());
                    holder.dateofpurchase.setText(Entry.GetDateOfPurchase().toString());
                }
            
                @Override
                public int getItemCount()
                {
                    return Entries.size();
                }
            
                @RequiresApi(api = Build.VERSION_CODES.O)
                public static class ViewHolder extends RecyclerView.ViewHolder
                {
                    final TextView purchase;
                    final TextView cost;
                    final TextView dateofpurchase;
                    ViewHolder(View view)
                    {
                        super(view);
                        purchase = (TextView) view.findViewById(R.id.textviewlist_purchase);
                        cost = (TextView) view.findViewById(R.id.textviewlist_cost);
                        dateofpurchase = (TextView) view.findViewById(R.id.textviewlist_dataofpurchase);
                    }
                }
            }
            
            MainActivity
           package com.example.personalaccounting;
        
        import android.app.Activity;
        import android.content.Intent;
        import android.graphics.Bitmap;
        import android.net.Uri;
        import android.os.Build;
        import android.os.Bundle;
        
        
        import androidx.annotation.Nullable;
        import androidx.annotation.RequiresApi;
        import androidx.appcompat.app.AppCompatActivity;
        import androidx.appcompat.widget.Toolbar;
        import androidx.recyclerview.widget.RecyclerView;
        
        
        import android.provider.MediaStore;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.view.View;
        import android.widget.Button;
        import android.widget.ImageView;
        import android.widget.TextView;
        import android.widget.Toast;
        
        import java.io.IOException;
        import java.time.LocalDate;
        import java.util.ArrayList;
        
        public class MainActivity extends AppCompatActivity
        {
        //Мобільне застосування «Особиста бухгалтерія»
            private ImageView ProfileImage;
            private MainActivity mainActivity;
            ArrayList<CountingEntry> countingEntries;
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            protected void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
                mainActivity = this;
                countingEntries = new ArrayList<CountingEntry>();
                setContentView(R.layout.activity_main);
                Toolbar toolbar = findViewById(R.id.toolbar);
                setSupportActionBar(toolbar);
                //
                ProfileImage = (ImageView)findViewById(R.id.Profile_Image);
                ProfileImage.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v)
                    {
                        Intent gallery = new Intent();
                        gallery.setType("image/*");
                        gallery.setAction(Intent.ACTION_GET_CONTENT);
                        startActivityForResult(Intent.createChooser(gallery,"Sellect Picture"), 1);
                    }
                });
                //
                Button button = (Button)findViewById(R.id.button2);
                button.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v)
                    {
                            countingEntries.add(new CountingEntry("Coca Cola",300,LocalDate.now()));
                            countingEntries.add(new CountingEntry("Pepsi",500,LocalDate.now()));
                            RecyclerView recyclerView = (RecyclerView) findViewById(R.id.RecyclerList);
                            CountingEntry_Adapter countingEntry_adapter = new CountingEntry_Adapter(mainActivity, countingEntries);
                            recyclerView.setAdapter(countingEntry_adapter);
                    }
                });
            }
        
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
            {
                super.onActivityResult(requestCode, resultCode, data);
                if(resultCode == RESULT_OK && requestCode == 1)
                {
                    Uri imageUri = data.getData();
                    try
                    {
                        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
                        ProfileImage.setImageBitmap(bitmap);
                    }
                    catch (IOException ex)
                    {
                        ex.printStackTrace();
                    }
                }
                if(resultCode == RESULT_OK && requestCode == 2)
                {
                    
                    CountingEntry countingEntry;
                    countingEntry = (CountingEntry) data.getParcelableExtra("CountingEntry");
                    countingEntries.add(countingEntry);
        
                }
            }
        
            @Override
            public boolean onCreateOptionsMenu(Menu menu)
            {
                getMenuInflater().inflate(R.menu.menu_main, menu);
                return true;
            }
        
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public boolean onOptionsItemSelected(MenuItem item)
            {
                int id = item.getItemId();
                if (id == R.id.action_Add)
                {
                    Intent intent = new Intent(this, Activity_AddNewCountingEntry.class);
                    startActivityForResult(intent,2);
                    return true;
                }
                return super.onOptionsItemSelected(item);
            }
        }
   
   Текст ошибки
    I/sonalaccountin: Background young concurrent copying GC freed 10226(1085KB) AllocSpace objects, 0(0B) LOS objects, 91% free, 2343KB/26MB, paused 7.947ms total 32.117ms
    E/sonalaccountin: Invalid ID 0x0000012c.
    D/AndroidRuntime: Shutting down VM
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.personalaccounting, PID: 2057
        android.content.res.Resources$NotFoundException: String resource ID #0x12c
            at android.content.res.Resources.getText(Resources.java:444)
            at android.widget.TextView.setText(TextView.java:6412)
            at com.example.personalaccounting.CountingEntry_Adapter.onBindViewHolder(CountingEntry_Adapter.java:40)
            at com.example.personalaccounting.CountingEntry_Adapter.onBindViewHolder(CountingEntry_Adapter.java:15)
            at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
            at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
            at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
            at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
            at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
            at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
            at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
            at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
            at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
            at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
            at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
            at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
            at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1855)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
            at com.android.internal.policy.DecorView.onLayout(DecorView.java:784)
            at android.view.View.layout(View.java:22844)
            at android.view.ViewGroup.layout(ViewGroup.java:6389)
            at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3470)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2938)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
            at android.view.Choreographer.doCallbacks(Choreographer.java:796)
            at android.view.Choreographer.doFrame(Choreographer.java:731)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
    E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:938)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:223)
            at android.app.ActivityThread.main(ActivityThread.java:7656)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
    I/Process: Sending signal. PID: 2057 SIG: 9
6
  • 1
    Если вылетает - то в логах будет описание и место ошибки. Добавьте эти 2 детали в вопрос - с ними вам помочь будет легко, без них - очень сложно, долго, почти невозможно.
    – ЮрийСПб
    16 апр 2021 в 9:27
  • Зачем дважды написали код адаптера?
    – Circassian
    16 апр 2021 в 9:29
  • Не знаю какой вы код-конвенции придерживаетесь, но в широких кругах принято название параметров, проперти и методов писать с маленькой буквы. С заглавной буквы пишутся только названия классов. И не принято в названии классов использовать нижнее подчеркивание. Перенос открывающей скобки на следующую строку тоже моветон.
    – Circassian
    16 апр 2021 в 9:31
  • @ЮрийСПб Добавил описание ошибки и MainActivity 16 апр 2021 в 9:44
  • Ошибка говорит о том, что вы устанавливаете в качестве текста число. Система думает что это идентификатор ресурса и пытается его найти, не находит и выбрасывает исключение. Перед установкой числа в текствью, кастните его в строку(toString())
    – Circassian
    16 апр 2021 в 9:46

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.