4Manuals

  • PDF Cloud HOME

java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“ void com …. views.NavigationBar.offLeftImage()” Download

    春季启动-Couchbase AbstractCouchbaseConfiguration-如何避免覆盖不必要的方法 如何在Android中使用WebRTC缩放相机 我不知道(未解决的编译问题:) Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 如何将动态值传递给渐变xml 加载数据并推送到未显示的RecyclerView中 调用Model类的函数时出现java.lang.NullPointerException 字符串数组在for循环中初始化时忽略索引0 从网络加载图像时,“接收到完整的报头之前关闭连接 Spring MVC @ModelAttribute未填充AJAX发布请求

我的活动代码

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.glossyglobe.R;
import com.glossyglobe.adapters.AdapterPortfolio;
import com.glossyglobe.gg.GGActivity;
import com.glossyglobe.gg.GGApplication;
import com.glossyglobe.models.ClientModel;
import com.glossyglobe.models.MasterQueue;
import com.glossyglobe.models.Order;
import com.glossyglobe.models.Portfolio.Element;
import com.glossyglobe.models.Router;
import com.glossyglobe.models.Settings;
import com.glossyglobe.models.commands.cmdBalanceGet;
import com.glossyglobe.models.commands.eventCommand;
import com.glossyglobe.models.events.eventMasterQueueUpdate;
import com.glossyglobe.models.events.eventOrderCancel;
import com.glossyglobe.models.events.eventOrderChange;
import com.glossyglobe.models.events.eventUserBalanceChanged;
import com.glossyglobe.models.stat.GGStatic;
import com.glossyglobe.services.EventGathering;
import com.glossyglobe.views.ImageGalleryOverview;
import com.glossyglobe.views.NavigationBar;
import com.glossyglobe.views.RecyclerItemOffsetDecoration;
import com.squareup.picasso.Picasso;
import com.stfalcon.frescoimageviewer.ImageViewer;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONObject;

import java.util.List;
import java.util.Locale;
import java.util.Set;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import utils.OrderBlankUtils;
import utils.OrderUtils;
import utils.RestUtils;
import utils.TextUtils;

/**
 * Created by define on 11.09.15.
 */

@EActivity(R.layout.v5_activity_confirm_master)
public class ActivityConfirmMaster extends GGActivity {

    private static final String TAG = GGApplication.TAG + "AConfMaster";

    protected int masterId = -1;
    protected long orderId = -1L;
    MasterQueue.FoundMaster master = null;
    protected Long currentPortfolioMasterId = null;

    @ViewById
    protected NavigationBar navigationBar;

    @ViewById
    public RatingBar userRating;

    @ViewById(R.id.imageAvatar)
    protected ImageView imageAvatar;

    @ViewById
    protected TextView tvMasterName;

    @ViewById
    protected RecyclerView recyclePortfolio;
    protected AdapterPortfolio adapter;
    @ViewById
    protected LinearLayout layoutPortfolio;

    @ViewById(R.id.tvPrice)
    protected TextView tvPrice;

//    @ViewById(R.id.tvOldPrice)
//    protected TextView tvOldPrice;

//    @ViewById(R.id.image_Quality)
//    protected ImageView imageQuality;
//    @ViewById(R.id.qualitySeparator)
//    protected View qualitySeparator;
    @ViewById
    protected TextView tvQuality;


    @ViewById
    protected TextView tvVATNotice;

    @ViewById
    protected TextView tvMasterArrivalTime;

//    @ViewById(R.id.recycleViewBasketItems)
//    protected RecyclerView basketItemList;
//    protected AdapterBasketItems adapterItems;

    @ViewById
    protected TextView tvServicesSimplify;

    @ViewById(R.id.layoutTotalPrice)
    protected LinearLayout layoutTotalPrice;

    @ViewById
    protected LinearLayout layoutMasterAbout;
    @ViewById
    protected TextView tvAbout;


    @ViewById
    protected LinearLayout layoutLanguages;
    @ViewById
    protected ImageView flagEn;
    @ViewById
    protected ImageView flagRu;
    @ViewById
    protected ImageView flagAr;
//    @ViewById
//    protected ImageView flagCh;

    @AfterViews
    public void afterShow(){
        navigationBar.offLeftImage();
        navigationBar.setTitle(getString(R.string.master_found_title));

//        tvOldPrice.setPaintFlags(tvOldPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                if (Settings.tempMasterQuality) {
//            qualitySeparator.setVisibility(View.VISIBLE);
//            imageQuality.setVisibility(View.VISIBLE);
                    tvQuality.setVisibility(View.VISIBLE);
                } else {
//            qualitySeparator.setVisibility(View.GONE);
//            imageQuality.setVisibility(View.GONE);
                    tvQuality.setVisibility(View.GONE);
                }
        updateMasterView();

        cmdBalanceGet
                .create()
                .exec();
    }

    private void updateMasterView() {
        ClientModel client = Router.instance().getModel();

        master = ClientModel.instance().getMasterQueue().getFirst();

        if (GGStatic.instance().getVAT() != 0){
            tvVATNotice.setVisibility(View.VISIBLE);
        } else {
            tvVATNotice.setVisibility(View.GONE);
        }

        if (master != null){
            if (currentPortfolioMasterId == null ||
                    !currentPortfolioMasterId.equals(master.portfolio.getUserId())){
                adapter = null;
                currentPortfolioMasterId = master.portfolio.getUserId();
            }
            masterId = master.id;
            orderId = master.orderId;


            tvMasterName.setText(TextUtils.masterNamingPolicy(
                    master.firstname,
                    master.lastname,
                    master.nickname
            ));

            userRating.setRating((float) master.rating);

            if (android.text.TextUtils.isEmpty(master.image)) {
                imageAvatar.setImageResource(R.drawable.no_photo_default);
            } else {
                Picasso.with(this)
                        .load(master.image)
                        .placeholder(R.drawable.no_photo_default)
                        .noFade()
                        .into(imageAvatar);
            }

            Order order = client.orderQueue().findOrder(orderId);

            tvMasterArrivalTime.setText(OrderUtils.willArriveAt(this,master.arrival_time));

            if (order != null) {

                double price = (double) master.price / GGStatic.instance().getCurrencyDecimalDivider();
                int possibleBonus = OrderBlankUtils.calcDiscount(
                        price,
                        client.balance().getDiscount(order.discountId));
                Log.e(TAG, "" + order.discountId  + " - " + possibleBonus);
                double totalPrice = price - possibleBonus;
                if (totalPrice < 0)
                    totalPrice = 0;

                String totalPriceCurrency = GGStatic.instance().getCurrencyISO(); //masterId.currency

                tvPrice.setText(
                        OrderUtils.getServicePriceFromTo(
                                this,
                                totalPrice,
                                totalPrice,
                                totalPriceCurrency));

//                if (possibleBonus > 0 ){
//                    tvOldPrice.setVisibility(View.VISIBLE);
//                    tvOldPrice.setText(
//                            OrderUtils.getServicePriceFromTo(
//                                    this,
//                                    price,
//                                    price,
//                                    totalPriceCurrency)
//                    );
//                } else {
//                    tvOldPrice.setVisibility(View.GONE);
//                }


                setGrade(master.grade);
                setLanguages(master.languages);


                tvServicesSimplify.setText(OrderUtils.getOrderAsText(this,order));
//                if (adapterItems == null) {
//                    Basket basket = new Basket();
//                    for (Long serviceId : order.servicesIdList) {
//                        GGService service = GGStatic.instance().getServices(serviceId);
//                        if (service != null)
//                            basket.addService(service);
//                    }
//                    adapterItems = new AdapterBasketItems(this, null, null, basket,order.grade);
//                    basketItemList.setAdapter(adapterItems);
//                    basketItemList.setLayoutManager(new LinearLayoutManager(this));
//                }


                OrderBlankUtils.setTotalPriceWithBonus(
                        this,layoutTotalPrice,
                        order.currency,
                        order.getPriceMinCalc(),
                        order.getPriceMaxCalc(),
                        order.getBonusMinCalc(),
                        order.getBonusMaxCalc());

//                TextViewPlus tvName = (TextViewPlus) layoutTotalPrice.findViewById(R.id.tvName);
//                TextViewPlus tvPrice = (TextViewPlus) layoutTotalPrice.findViewById(R.id.tvPrice);
//
//                tvName.setText(getString(R.string.txt_order_total));
//                tvPrice.setText(OrderUtils.getServicePriceFromTo(this, order.getPriceMinCalc(),
//                        order.getPriceMaxCalc(),
//                        BuildConfig.isCurrencyReverse));

                if (!android.text.TextUtils.isEmpty(master.about)){
                    layoutMasterAbout.setVisibility(View.VISIBLE);
                    tvAbout.setText(master.about);
                } else {
                    layoutMasterAbout.setVisibility(View.GONE);
                }

            } else {
                layoutMasterAbout.setVisibility(View.GONE);
                Log.e(TAG, "NO Order for id - " + orderId);
            }
        } else {
            currentPortfolioMasterId = null;
        }

        validatePortfolio();
    }

    private void setLanguages(Set<String> langs) {
        if (langs.size() > 0){
            layoutLanguages.setVisibility(View.VISIBLE);
            if (langs.contains("en")){
                flagEn.setVisibility(View.VISIBLE);
            } else {
                flagEn.setVisibility(View.GONE);
            }
            if (langs.contains("ru")){
                flagRu.setVisibility(View.VISIBLE);
            } else {
                flagRu.setVisibility(View.GONE);
            }
            if (langs.contains("ar")){
                flagAr.setVisibility(View.VISIBLE);
            } else {
                flagAr.setVisibility(View.GONE);
            }
        }else{
            layoutLanguages.setVisibility(View.GONE);
        }
    }

    private void validatePortfolio() {
        if (currentPortfolioMasterId != null &&
                master != null &&
                master.portfolio.getSortedList().size() > 0 ){
            layoutPortfolio.setVisibility(View.VISIBLE);

            if (adapter == null){
                adapter = new AdapterPortfolio(
                        this,
                        master.portfolio,
                        clickView);
                recyclePortfolio.setAdapter(adapter);
                recyclePortfolio.setLayoutManager(
                        new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
                );
                recyclePortfolio.addItemDecoration(
                        new RecyclerItemOffsetDecoration(
                                (int) getResources().getDisplayMetrics().density * 3));

                adapter.notifyDataSetChanged();
            }

        } else {
            layoutPortfolio.setVisibility(View.GONE);
        }
    }


    @Subscribe
    protected void onPromoBalanceChange(eventUserBalanceChanged event){
        updateMasterView();
    }

    @Subscribe
    public void onEvent(eventOrderCancel event) {
        Order order = event.getOrder();
        if (order != null &&
                order.id == orderId){
            goToNextState();
        }
    }

    @Subscribe
    public void onEvent(eventMasterQueueUpdate event){
        goToNextState();
    }


//    public void setGrade(int grade){
//        int resId = R.drawable.icon_quality_1_small;
//        switch (grade){
//            case 2:{
//                resId = R.drawable.icon_quality_2_small;
//                break;
//            }
//            case 3:{
//                resId = R.drawable.icon_quality_3_small;
//                break;
//            }
//        }
//
//        imageQuality.setImageResource(resId);
//    }


    public void setGrade(int grade){
        Integer resId = OrderUtils.gradeTitleResId(grade);

        if (resId != null) {
            tvQuality.setVisibility(View.VISIBLE);
            tvQuality.setText(resId);
        } else {
            tvQuality.setVisibility(View.GONE);
        }
    }

    private void goToNextState(){
        GGApplication.instance.mainHandler.post(
                new Runnable() {
                    @Override
                    public void run() {
                        if (Router.instance().getModel().getMasterQueue().getFirst() != null) {
                            afterShow();
                        } else {
                            GGApplication.activitySwitcher(ActivityConfirmMaster.this);
                        }
                    }
                });
    }

    @Click(R.id.button_accept)
    protected void onAccept(){
        if (orderId != -1 && masterId != -1) {

            GGApplication.apiS().approveMaster(
                    GGApplication.getVersionHeader(),
                    GGStatic.instance().getVersion(),
                    GGApplication.getTokenHeader(),
                    orderId,
                    masterId
            ).enqueue(new Callback<ResponseBody>() {
                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    JSONObject result = RestUtils.getJSONWithErrorControl(response);

                    if (RestUtils.isOK(result)) {
                        EventGathering.purchase(
                                ActivityConfirmMaster.this,
                                orderId,
                                ClientModel.instance().getGender());

                        Router.instance().getModel().getMasterQueue().removeMaster(masterId);

                        eventCommand.log("onApproveMaster", result);
                        goToNextState();
                    } else {
                        GGApplication.showToast(RestUtils.getErrorMessage(result));
                    }

                    cmdBalanceGet.create().exec();
                }

                @Override
                public void onFailure(Call<okhttp3.ResponseBody> call, Throwable t) {
                    GGApplication.serverTempHandler();
                    Log.e(TAG, "approveMaster: FAILURE : " + t.getMessage());
                }
            });

        } else {
            eventOrderChange.post(null);
        }
        //back();
    }

    @Click(R.id.button_reject)
    protected void onDecline(){
        if (orderId != -1 && masterId != -1) {

            GGApplication.apiS().declineMaster(
                    GGApplication.getVersionHeader(),
                    GGStatic.instance().getVersion(),
                    GGApplication.getTokenHeader(),
                    orderId,
                    masterId
            ).enqueue(new Callback<ResponseBody>() {
                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    JSONObject result = RestUtils.getJSONWithErrorControl(response);

                    if (RestUtils.isOK(result)) {
                        Router.instance().getModel().getMasterQueue().removeMaster(masterId);
                        // TODO: 25/06/2017 marketing metrics - masterId decline


                        eventCommand.log("onDeclineMaster", result);
                        goToNextState();
                    } else {
                        GGApplication.showToast(RestUtils.getErrorMessage(result));
                    }
                }

                @Override
                public void onFailure(Call<okhttp3.ResponseBody> call, Throwable t) {
                    GGApplication.serverTempHandler();
                    Log.e(TAG, "declineMaster: FAILURE : " + t.getMessage());
                }
            });

        } else {

            eventOrderChange.post(null);
        }

        //back();
    }

    @Override
    public void onBackPressed() {
        back();
    }

    public void back(){
//        finish();
//        LocUtils.animBackward(this);
    }

    public View.OnClickListener clickView = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Integer pos = (Integer) view.getTag();

            if (master != null) {
                final List<Element> images = master.portfolio.getSortedList();

                final ImageGalleryOverview overlay = new ImageGalleryOverview(ActivityConfirmMaster.this);

                ImageViewer.OnImageChangeListener changeListener =
                        new ImageViewer.OnImageChangeListener() {
                            @Override
                            public void onImageChange(int position) {
                                String text = String.format(Locale.getDefault(),
                                        "%d/%d", position + 1, images.size());
                                overlay.setTitle(text);
                                overlay.buttonRight.setTag(position);
                            }
                        };

                final ImageViewer viewer = new ImageViewer.Builder<>(ActivityConfirmMaster.this,
                        images)
                        .setFormatter(new ImageViewer.Formatter<Element>() {
                            @Override
                            public String format(Element customImage) {
                                return customImage.url;
                            }
                        })
                        .setStartPosition(pos)
                        .setOverlayView(overlay)
                        .setImageChangeListener(changeListener)
                        .build();

                overlay.setButtonLeftClick(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        viewer.onDismiss();
                    }
                });



                viewer.show();
            }

        }
    };

    public static Intent launcher(Context context) {
        Intent intent = new Intent(context, ActivityConfirmMaster.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return intent;
    }
}

应用程序有2个版本:向导和客户端 当客户端创建订单时,向导会看到并接受订单,它等待客户端的确认,但是会发生错误java.lang.NullPointerException:尝试调用虚拟方法'void com.glossyglobe.views.NavigationBar.offLeftImage( )'在空对象引用上 帮助我找到解决方案,我已经折磨了一天以上

0 个答案:

没有答案



Similar searches
    循环在SAS中拆分巨大的数据集并将较小的数据集导出到CSV文件 如果尚未将数据附加到json文件中 在Microsoft VSC上将原始未分配的数据从json文件导出到HTML文件 如何从MEF中的ComposablePartDefinition / ComposablePart创建对象 值更改时ng模型不会更新