该应用程序应该有一个从左侧拉出并显示各种 Activity 的抽屉导航,但是一旦将导航栏添加到 XML activity_homescreen 文档中,该应用程序就会在启动时立即崩溃。
HomeScreen.java
package com.t99sdevelopment.centralized;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Toolbar;
public class HomeScreen extends AppCompatActivity {
/*
Intent intentHome = new Intent(this, HomeScreen.class);
Intent intentAnnouncements = new Intent(this, AnnouncementsScreen.class);
Intent intentSchedule = new Intent(this, ScheduleScreen.class);
Intent intentCalendar = new Intent(this, CalendarScreen.class);
Intent intentContactBook = new Intent(this, ContactBookScreen.class);
Intent intentSportsSchedule = new Intent(this, SportsScheduleScreen.class);
Intent intentFrontAndCentral = new Intent(this, FrontAndCentralScreen.class);
Intent intentMap = new Intent(this, MapScreen.class);
Intent intentAccount = new Intent(this, AccountScreen.class);
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homescreen);
setTheme(R.style.AppTheme);
}
/*
private void goToHome(View view){ startActivity(intentHome ); }
private void goToAnnouncements(View view){ startActivity(intentAnnouncements ); }
private void goToSchedule(View view){ startActivity(intentSchedule); }
private void goToCalendar(View view){ startActivity(intentCalendar); }
private void goToContactBook(View view){ startActivity(intentContactBook); }
private void goToSportsSchedule(View view){ startActivity(intentSportsSchedule); }
private void goToFrontAndCentral(View view){ startActivity(intentFrontAndCentral); }
private void goToMap(View view){ startActivity(intentMap); }
private void goToAccount(View view){ startActivity(intentAccount); }
*/
}
activity_homescreen.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
android:background="@color/trojanBlack">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/actionbar" />
<ImageView
android:id="@+id/ImageView_trojanHead"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="150dp"
android:src="@drawable/trojan"
android:scaleType="centerCrop" />
<TextView
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginTop="100dp"
android:text="School is"
android:paddingTop="5dp"
android:textSize="30sp"
android:textColor="@color/trojanBlack"
android:textAlignment="center"
android:background="@drawable/schoolbutton"
android:radius="5dp"/>
<RelativeLayout
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginTop="-100dp">
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/refresh"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:text="OPEN"
android:textSize="40sp"
android:textColor="@color/trojanBlack"
android:textAlignment="center"
android:paddingTop="45dp" />
</RelativeLayout>
<TextView
android:layout_width="250dp"
android:layout_height="50dp"
android:background="#FFFFFF"
android:layout_marginTop="10dp" />
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:menu="@menu/navigationdraweritems"
app:headerLayout="@layout/nav_header" />
</android.support.v4.widget.DrawerLayout>
按原样使用这些文件,应用程序会崩溃,但如果我按如下方式更改 activity_homescreen.xml(注释掉导航 View 小部件)...
activity_homescreen.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
android:background="@color/trojanBlack">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/actionbar" />
<ImageView
android:id="@+id/ImageView_trojanHead"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="150dp"
android:src="@drawable/trojan"
android:scaleType="centerCrop" />
<TextView
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginTop="100dp"
android:text="School is"
android:paddingTop="5dp"
android:textSize="30sp"
android:textColor="@color/trojanBlack"
android:textAlignment="center"
android:background="@drawable/schoolbutton"
android:radius="5dp"/>
<RelativeLayout
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginTop="-100dp">
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/refresh"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:text="OPEN"
android:textSize="40sp"
android:textColor="@color/trojanBlack"
android:textAlignment="center"
android:paddingTop="45dp" />
</RelativeLayout>
<TextView
android:layout_width="250dp"
android:layout_height="50dp"
android:background="#FFFFFF"
android:layout_marginTop="10dp" />
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!--
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:menu="@menu/navigationdraweritems"
app:headerLayout="@layout/nav_header" />
-->
</android.support.v4.widget.DrawerLayout>
一切正常,除了抽屉导航没有被包含/工作。有没有人遇到过这个问题,或者更好的是,有人知道如何解决它吗?我需要抽屉导航正常工作,但它似乎让我的应用程序崩溃了。
logcat 超出了最大字符数,所以这里是 github gist .
最佳答案
绝对是您的 logcat 中缺少方法的问题:
Caused by: android.view.InflateException: Couldn't resolve menu item onClick handler goToHome in class com.t99sdevelopment.centralized.HomeScreen
Caused by: java.lang.NoSuchMethodException: goToHome [interface android.view.MenuItem]
关于java - 错误膨胀类 android.support.design.widget.NavigationView [启动时崩溃],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33613058/
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee