从改造中获取数据并将其保存在活动的Android数据库中时出错

时间:2018-09-03 09:36:41

标签: activeandroid

我遇到一个问题,当我在Retrofit上使用活动的android时,我的应用程序崩溃。我想显示类别列表,并且该列表显示的项目没有活动的android数据库...但是当我添加活动的android时离线支持数据库我的应用程序崩溃

这是我的代码

public class Category extends AppCompatActivity {
    private ListView listview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category);
        listview = (ListView) findViewById(R.id.lv);

        ActiveAndroid.initialize(this);
        Window window = getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            window.setStatusBarColor(getColor(R.color.login_statusbar_color));
        }
        else {
            window.setStatusBarColor(getResources().getColor(R.color.login_statusbar_color));
        }

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int i, long id) {
                Intent intent = new Intent(Category.this , Home_Activity.class);
                intent.putExtra("CategoryName" , listview.getItemAtPosition(i).toString());
                startActivity(intent);

            }
        });
        getcategory();


    }

    public void getcategory(){

        Call<List<UserCatagories>> call = RetrofitClient.getInstance().getApi().getCatagories();
        call.enqueue(new Callback<List<UserCatagories>>() {
            @Override
            public void onResponse(Call<List<UserCatagories>> call, Response<List<UserCatagories>> response) {
                List<UserCatagories> catagories =response.body();
                for (UserCatagories C : catagories){

//                   C.save();

                    Log.d("catagories" , C.getCatagories() );

                    String[] catagoriesname = new String[catagories.size()];
                    for (int i=0 ; i<catagories.size() ; i++){
                        catagoriesname[i]= catagories.get(i).getCatagories();
                    }
                    listview.setAdapter(new ArrayAdapter<String>(
                            getApplicationContext() ,
                            android.R.layout.simple_spinner_dropdown_item,
                            catagoriesname
                    ){

                        @Override
                        public View getView(int position, View convertView, ViewGroup parent) {
                            View view =super.getView(position, convertView, parent);
                            TextView textView=(TextView) view.findViewById(android.R.id.text1);
                            textView.setTextColor(Color.BLACK);
                            return view;
                        }
                        });



                }
            }

            @Override
            public void onFailure(Call<List<UserCatagories>> call, Throwable t) {
                Toast.makeText(Category.this , t.getMessage() , Toast.LENGTH_SHORT).show();
            }
        });

    }
//    public static void fullDatabaseReset() {
//        try {
//            clearCache();
//            ActiveAndroid.dispose();
//
//        } catch (Exception e) {
//
//        }
//    }
}



here is my model class

你好,我遇到一个问题,当我将活动的android与Retrofit一起使用时...我的应用程序崩溃。我想显示类别列表,并且该列表显示的项目没有活动的android数据库...但是当我添加时离线支持的活动android数据库正在崩溃

@Table(name = "Categories")
public class UserCatagories extends Model {

    @Column(name = "category_name")
    @SerializedName("title")
    @Expose
    private String catagories;


    public UserCatagories(){
        super();
    }

    public UserCatagories(String catagories) {

        super();
        this.catagories = catagories;


    }

    public String getCatagories() {
        return catagories;
    }
}

0 个答案:

没有答案