Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THE APP CRASHED #1

Open
smartevesoft opened this issue Mar 5, 2018 · 0 comments
Open

THE APP CRASHED #1

smartevesoft opened this issue Mar 5, 2018 · 0 comments

Comments

@smartevesoft
Copy link

the app has crashed
at rocks.athrow.android_inventory_app.ItemListActivity.setupRecyclerView(ItemListActivity.java:62)
at rocks.athrow.android_inventory_app.ItemListActivity.onStart(ItemListActivity.java:51).

package rocks.athrow.android_inventory_app;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.View;

import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmResults;

public class ItemListActivity extends AppCompatActivity {
private static final String LOG_TAG = ItemListActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_list);


    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (toolbar != null) {
        toolbar.setTitle(getTitle());
    }
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    if (fab != null) {
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getApplicationContext(), ItemDetailDataEntry.class);
                startActivity(intent);

            }
        });
    }
}

@Override
protected void onStart() {
    super.onStart();
    View recyclerView = findViewById(R.id.item_list);
    assert recyclerView != null;
    setupRecyclerView((RecyclerView) recyclerView);

}

private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build();
    Realm.setDefaultConfiguration(realmConfig);
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    final RealmResults<Item> items = realm.where(Item.class).findAll();
    realm.commitTransaction();
    int size = items.size();
    Log.e(LOG_TAG, "size " + size);
    if (size > 0) {
        recyclerView.setAdapter(new ItemListAdapter(this, realm.where(Item.class).findAllAsync()));
        recyclerView.setHasFixedSize(true);
    }

}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant