0
こんにちは私はAndroidには新しく、すべてのアクティビティのアクションバーにロゴと検索ビューを追加しようとしています。私は自分の活動の1つにロゴを実装しようとしましたが、このエラーが発生し、アプリがクラッシュします。誰かがこれを取り除く方法を教えてもらえますか?私がやろうとしていることをするための他の方法がありますか?アクションバーにロゴを追加できないandroid
が、私はこのウェブサイトhttps://romannurik.github.io/AndroidAssetStudio/index.html
エラー
02-27 00:58:28.859 13851-13851/com.golstars.www.glostars E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.golstars.www.glostars, PID: 13851
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.golstars.www.glostars/com.golstars.www.glostars.MainFeed}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayShowHomeEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayShowHomeEnabled(boolean)' on a null object reference
at com.golstars.www.glostars.MainFeed$override.onCreate(MainFeed.java:96)
at com.golstars.www.glostars.MainFeed$override.access$dispatch(MainFeed.java)
at com.golstars.www.glostars.MainFeed.onCreate(MainFeed.java:0)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
マイmainfeedのonCreateメソッド
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_feed);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_action_logoandtext);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
activity_main_feed.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.golstars.www.glostars.MainFeed">
<include
layout="@layout/activity_test"
/>
<include
layout="@layout/fabs"
/>
</android.support.design.widget.CoordinatorLayout>
から直接アイコンをリサイズ
マニフェストファイル:onCreate
で
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.golstars.www.glostars">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:debuggable="true"
android:supportsRtl="true"
android:name="android.support.multidex.MultiDexApplication"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainFeed"
android:label="@string/title_activity_main_feed"
android:theme="@style/AppTheme" />
<activity
android:name=".user_profile"
android:label="@string/title_activity_user_profile"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Fabs"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".testfeed"
android:label="@string/title_activity_test"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".notification"
android:label="@string/title_activity_notification"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".upload"
android:label="@string/title_activity_upload"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".edit_profile"
android:label="@string/title_activity_edit_profile"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".competitionUser"
android:label="@string/title_activity_competition_user"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".competitionAll"
android:label="@string/title_activity_competition_all"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".imagefullscreen"
android:label="@string/title_activity_image_full_screen"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".commentModel"
android:label="@string/title_activity_comment_model"
android:theme="@style/AppTheme.NoActionBar"/>
</application>
</manifest>
を設定します。 –