Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改活动时应用程序崩溃_Android - Fatal编程技术网

Android 更改活动时应用程序崩溃

Android 更改活动时应用程序崩溃,android,Android,我一直致力于在我的应用程序中支持多个屏幕。但是,当我的屏幕被检测为480x800屏幕时,它会切换到该分辨率的活动,但此时它会崩溃 这是detect.java,它根据屏幕分辨率做出决定: package com.example.mywallpapers; import android.app.Activity; import android.content.Intent; import android.graphics.Point; import android.os.Build; import

我一直致力于在我的应用程序中支持多个屏幕。但是,当我的屏幕被检测为480x800屏幕时,它会切换到该分辨率的活动,但此时它会崩溃

这是detect.java,它根据屏幕分辨率做出决定:

package com.example.mywallpapers;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;

public class Detect extends Activity {

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        int width = 0;
        Point size = new Point();
        WindowManager w = getWindowManager();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

            w.getDefaultDisplay().getSize(size);

            width = size.x;
        } else {
            Display d = w.getDefaultDisplay();
            width = d.getWidth();
        }
        if (width == 480) {
                startActivity(new Intent(Detect.this, SevenTwentyOne.class));



        } else if (width == 720) {
            startActivity(new Intent("com.example.mywallpapers.FOUREIGHTONE"));
        } else {
            startActivity(new Intent("com.example.mywallpapers.FOUREIGHTONE"));
        }

    }



    }
这是我的第七十二个类(不是针对1280x720分辨率,而是针对480x800)

每当我在480x800手机上测试我的应用程序时,它都会因NullPointerExection而崩溃。你知道那是从哪里来的吗

这是logCat:

05-15 11:27:47.600: E/AndroidRuntime(31642): FATAL EXCEPTION: main
05-15 11:27:47.600: E/AndroidRuntime(31642): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mywallpapers/com.example.mywallpapers.SevenTwentyOne}: java.lang.NullPointerException
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.os.Looper.loop(Looper.java:137)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.main(ActivityThread.java:4898)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at java.lang.reflect.Method.invokeNative(Native Method)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at java.lang.reflect.Method.invoke(Method.java:511)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at dalvik.system.NativeStart.main(Native Method)
05-15 11:27:47.600: E/AndroidRuntime(31642): Caused by: java.lang.NullPointerException
05-15 11:27:47.600: E/AndroidRuntime(31642):    at com.example.mywallpapers.SevenTwentyOne.onCreate(SevenTwentyOne.java:90)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.Activity.performCreate(Activity.java:5206)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
05-15 11:27:47.600: E/AndroidRuntime(31642):    ... 11 more

logcat中的空指针在SevenTwentyOne.java中的第90行,你能突出显示那一行吗?发布你的“四八八分之一”布局文件你的布局文件中有按钮Wap50吗对不起,这是不可能的,如果没有xml,我会在问题正文中获得太多字符,最可能的答案是@Iftikar Urrhman Khan评论。Wap50不在布局中,因为如果找不到视图,findViewById()将返回null。
05-15 11:27:47.600: E/AndroidRuntime(31642): FATAL EXCEPTION: main
05-15 11:27:47.600: E/AndroidRuntime(31642): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mywallpapers/com.example.mywallpapers.SevenTwentyOne}: java.lang.NullPointerException
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.os.Looper.loop(Looper.java:137)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.main(ActivityThread.java:4898)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at java.lang.reflect.Method.invokeNative(Native Method)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at java.lang.reflect.Method.invoke(Method.java:511)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at dalvik.system.NativeStart.main(Native Method)
05-15 11:27:47.600: E/AndroidRuntime(31642): Caused by: java.lang.NullPointerException
05-15 11:27:47.600: E/AndroidRuntime(31642):    at com.example.mywallpapers.SevenTwentyOne.onCreate(SevenTwentyOne.java:90)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.Activity.performCreate(Activity.java:5206)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-15 11:27:47.600: E/AndroidRuntime(31642):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
05-15 11:27:47.600: E/AndroidRuntime(31642):    ... 11 more