Java 安卓应用程序在按横向按钮时崩溃

Java 安卓应用程序在按横向按钮时崩溃,java,android,xml,crash,android-orientation,Java,Android,Xml,Crash,Android Orientation,当我旋转到横向并按下主活动上的按钮时,应用程序崩溃。如果我按下纵向中的按钮,在辅助活动中切换到横向,然后在横向中返回到主活动,则不会崩溃。它会崩溃,当我按下那个按钮在景观,我不知道如何或为什么它这样做 您是否需要查看其他文件?请让我知道,第一次张贴在这里 这是按钮主活动中的xml代码 <Button android:id="@+id/button_acknowledgements" android:layout_width="wrap_co

当我旋转到横向并按下主活动上的按钮时,应用程序崩溃。如果我按下纵向中的按钮,在辅助活动中切换到横向,然后在横向中返回到主活动,则不会崩溃。它会崩溃,当我按下那个按钮在景观,我不知道如何或为什么它这样做

您是否需要查看其他文件?请让我知道,第一次张贴在这里

这是按钮主活动中的xml代码

<Button 
            android:id="@+id/button_acknowledgements"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:text="@string/acknowledgments"
            android:onClick="acknowledgments"
            android:textColor="#FFFFFF"/>
这就是activity_aknowledments.xml文件中的全部内容

<WebView 
        android:id="@+id/AckWebView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
我还将android:configChanges=keyboardHidden | orientation | screenSize限定符包含在活动下的android清单中

02-09 17:59:08.198: E/AndroidRuntime(22749): FATAL EXCEPTION: main
02-09 17:59:08.198: E/AndroidRuntime(22749): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.spacepowerexchangeordersubmission/com.example.spacepowerexchangeordersubmission.Acknowledgments}: java.lang.NullPointerException`
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.os.Looper.loop(Looper.java:137)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.main(ActivityThread.java:5419)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at java.lang.reflect.Method.invoke(Method.java:525)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at            dalvik.system.NativeStart.main(Native Method)
02-09 17:59:08.198: E/AndroidRuntime(22749): Caused by: java.lang.NullPointerException
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.example.spacepowerexchangeordersubmission.Acknowledgments.setupActionBar(Acknowledgments.java:35)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.example.spacepowerexchangeordersubmission.Acknowledgments.onCreate(Acknowledgments.java:19)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.Activity.performCreate(Activity.java:5372)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
02-09 17:59:08.198: E/AndroidRuntime(22749):    ... 11 more

堆栈跟踪,错误消息??去掉android:configChanges=keyboardHidden | orientation | Screen Size这是一种黑客行为,甚至谷歌都说,只有当你真正知道自己在做什么时,才应该将其作为最后手段。相反,阅读并学习活动的生命周期和相应的代码,否则你只会用hack隐藏其他bug。其次,编辑您的问题,并包括来自logcat的堆栈跟踪。
package com.example.spacepowerexchangeordersubmission;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class Acknowledgments extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_acknowledgments);
        // Show the Up button in the action bar.
        setupActionBar();

        WebView web = (WebView) findViewById(R.id.AckWebView);
        web.getSettings().setJavaScriptEnabled(true);
        web.getSettings().setLoadsImagesAutomatically(true);
        web.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); 
        web.getSettings().setDomStorageEnabled(true);
        web.loadUrl("http://www.prism.gatech.edu/~rpanjwani3/");

    }

    /**
     * Set up the {@link android.app.ActionBar}.
     */
    private void setupActionBar() {

        getActionBar().setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.acknowledgments, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void onConfigurationChanged(Configuration newConfig){
        super.onConfigurationChanged(newConfig);
    }


}
02-09 17:59:08.198: E/AndroidRuntime(22749): FATAL EXCEPTION: main
02-09 17:59:08.198: E/AndroidRuntime(22749): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.spacepowerexchangeordersubmission/com.example.spacepowerexchangeordersubmission.Acknowledgments}: java.lang.NullPointerException`
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.os.Looper.loop(Looper.java:137)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.main(ActivityThread.java:5419)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at java.lang.reflect.Method.invoke(Method.java:525)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at            dalvik.system.NativeStart.main(Native Method)
02-09 17:59:08.198: E/AndroidRuntime(22749): Caused by: java.lang.NullPointerException
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.example.spacepowerexchangeordersubmission.Acknowledgments.setupActionBar(Acknowledgments.java:35)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at com.example.spacepowerexchangeordersubmission.Acknowledgments.onCreate(Acknowledgments.java:19)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.Activity.performCreate(Activity.java:5372)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
02-09 17:59:08.198: E/AndroidRuntime(22749):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
02-09 17:59:08.198: E/AndroidRuntime(22749):    ... 11 more