jjzjj

android - 无法构建发布应用程序,gradle 说找不到封闭方法 'boolean onCreateOptionsMenu(android.view.Menu)

coder 2023-12-23 原文

在 Debug模式下,应用程序运行平稳,但在 Release模式下尝试构建时,应用程序构建失败。

它给我一个错误提示 com.karriapps.smartsiddur.LocationsActivity$3:在程序类 com.karriapps.smartsiddur.LocationsActivity 中找不到封闭方法“boolean onCreateOptionsMenu(android.view.Menu)” 但是我现在在这个 Activity 中没有使用菜单。我以前有 beofre,但我删除了它。

package com.karriapps.smartsiddur;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.karriapps.smartsiddur.fragments.LocationSearchFragment;
import com.karriapps.smartsiddur.model.ElavationService;
import com.karriapps.smartsiddur.model.Location;
import com.karriapps.smartsiddur.model.listeners.LocationListener;
import com.karriapps.smartsiddur.model.response.LocationResponse;
import com.karriapps.smartsiddur.util.LocationHandler;
import com.karriapps.smartsiddur.util.SSApp;
import com.karriapps.smartsiddur.views.LocationViewHolder;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import io.realm.RealmResults;


public class LocationsActivity extends BaseActivity implements LocationSearchFragment.LocationSetListener {

    public static final String BUNDLE_LOCATION_ID = "location_id";
    public static final String BUNDLE_FROM_SEARCH = "from_search";
    public static final int RESPONSE_OK = 0;
    public static final int RESPONSE_SET = 1;

    private Toolbar mToolbar;
    private RecyclerView mLocationsRecyclerView;
    private View mCurrentLocation;
    private SearchView mSearchView;
    private List<LocationResponse.Feature> mLocationsSuggestion;
    private ArrayAdapter<String> mAdapter;
    private LocationsAdapter mLocationsAdapter;
    private RealmResults<Location> mLocations;
    private View mProgressBar;
    private boolean fromSearch;
    private LocationSearchFragment mLocationSearchFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        fromSearch = getIntent().getBooleanExtra(BUNDLE_FROM_SEARCH, false);

        setContentView(R.layout.activity_locations);
        mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
        mCurrentLocation = findViewById(R.id.location_activity_current_location);
        mProgressBar = findViewById(R.id.progressBar);

        mLocationsRecyclerView = (RecyclerView) findViewById(R.id.locationsList);
        mLocationsRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");

        loadLocations();
        mLocationsAdapter = new LocationsAdapter();
        mLocationsRecyclerView.setAdapter(mLocationsAdapter);
        mLocationsRecyclerView.setItemAnimator(new DefaultItemAnimator());

        mLocationSearchFragment = new LocationSearchFragment();

        LocationHandler.getInstance().setLocationListener(new LocationListener() {
            @Override
            public void onLocationFailure() {
                mProgressBar.setVisibility(View.GONE);
            }

            @Override
            public void onLocationAchieved(Location location) {
                SSApp.getInstance().addLocation(location);
                loadLocations();
                mLocationsAdapter.notifyDataSetChanged();
                mProgressBar.setVisibility(View.GONE);

                if (fromSearch) {
                    returnToCallingActivity();
                }
            }
        });

        findViewById(R.id.searchBtn).setOnClickListener(v -> {
            mLocationSearchFragment.show(getSupportFragmentManager(), "places");
        });
    }

    private void updateCurrentLocation() {
        LocationViewHolder locationViewHolder = new LocationViewHolder(mCurrentLocation);

        if (SSApp.getInstance().getLocation() != null) {
            locationViewHolder.bind(SSApp.getInstance().getLocation(), new LocationViewHolder.OnLocationItemOperation() {
                @Override
                public void onDeleteLocationClick(int position) {
                }

                @Override
                public void onDetailsChanged(int position, boolean inIsrael) {
                    updateIsInIsrael(SSApp.getInstance().getLocation(), inIsrael);
                }

                @Override
                public void onSetLocationClick(int position) {
                }
            });
        } else {
            locationViewHolder.bind(SSApp.getInstance().getLocation(), null);
        }
    }

    private void loadLocations() {
        mLocations = SSApp.getInstance()
                .getRealm()
                .where(Location.class)
                .equalTo("isActive", false)
                .findAll();

        updateCurrentLocation();
    }

    private void returnToCallingActivity() {
        Intent intent = new Intent();
        setResult(RESPONSE_SET, intent);
        finish();
    }

    private void updateIsInIsrael(Location location, boolean inIsrael) {
        if (location.isInIsrael() != inIsrael) {
            SSApp.getInstance().getRealm().beginTransaction();
            location.setIsInIsrael(inIsrael);
            SSApp.getInstance().getRealm().commitTransaction();
            mLocationsAdapter.notifyDataSetChanged();
            updateCurrentLocation();
        }
    }

    @Override
    public void onLocationSet(@NotNull ElavationService.LatLng latLng) {
        runOnUiThread(() -> {
            if (mLocationSearchFragment != null && mLocationSearchFragment.isVisible()) {
                mLocationSearchFragment.dismissAllowingStateLoss();
            }
            mProgressBar.setVisibility(View.VISIBLE);
        });
        LocationHandler.getInstance()
                .setLocation(latLng.getLatitude(),
                        latLng.getLongitude(),
                        false
                );
    }

    class LocationsAdapter extends RecyclerView.Adapter<LocationViewHolder> implements LocationViewHolder.OnLocationItemOperation {

        @Override
        public LocationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(LocationsActivity.this)
                    .inflate(R.layout.location_row, parent, false);
            return new LocationViewHolder(view);
        }

        @Override
        public void onBindViewHolder(LocationViewHolder holder, int position) {
            holder.bind(mLocations.get(position), this);
        }

        @Override
        public int getItemCount() {
            return mLocations == null ? 0 : mLocations.size();
        }

        @Override
        public void onDeleteLocationClick(int position) {
            SSApp.getInstance().removeLocation(mLocations.get(position));
            loadLocations();
            notifyItemRemoved(position);
        }

        @Override
        public void onSetLocationClick(int position) {
            SSApp.getInstance().setLocation(mLocations.get(position));
            returnToCallingActivity();
        }

        @Override
        public void onDetailsChanged(int position, boolean inIsrael) {
            updateIsInIsrael(mLocations.get(position), inIsrael);
        }
    }
}

出于某种原因,它似乎仍在寻找它,但我不知道为什么

最佳答案

您的发布构建中间件中可能有一些旧文件导致了问题,引用了不再存在的代码。

干净的重建应该摆脱它们。

关于android - 无法构建发布应用程序,gradle 说找不到封闭方法 'boolean onCreateOptionsMenu(android.view.Menu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57259994/

有关android - 无法构建发布应用程序,gradle 说找不到封闭方法 'boolean onCreateOptionsMenu(android.view.Menu)的更多相关文章

  1. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  2. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  3. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  4. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  5. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  6. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  7. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  8. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  9. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  10. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

随机推荐