0

我正在尝试为不同的屏幕尺寸制作布局。在我想要在我的三星 Galaxy Tab 2 7.0 上很好地显示相同的布局之后,我开始为我的智能手机制作一些按钮的基本布局。所以我按照android开发网站上的说明进行操作。

我首先创建了文件夹“layout-large”并创建了第二个布局,但这次是为平板电脑创建的,它不起作用。之后我尝试使用名为“layout-sw600dp”的文件夹并得到相同的结果,它崩溃了。我尝试使用调试模式,但由于某种原因这也不起作用。

LogCat 代码如下,希望有人能提供帮助。亲切的问候

08-29 10:56:56.125: E/AndroidRuntime(6457): FATAL EXCEPTION: main
08-29 10:56:56.125: E/AndroidRuntime(6457): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.quality_of_life/com.example.quality_of_life.MainActivity}: java.lang.NullPointerException
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.os.Looper.loop(Looper.java:137)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.ActivityThread.main(ActivityThread.java:4895)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at java.lang.reflect.Method.invokeNative(Native Method)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at java.lang.reflect.Method.invoke(Method.java:511)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at dalvik.system.NativeStart.main(Native Method)
08-29 10:56:56.125: E/AndroidRuntime(6457): Caused by: java.lang.NullPointerException
08-29 10:56:56.125: E/AndroidRuntime(6457):     at com.example.quality_of_life.MainActivity.addListenerOnButton(MainActivity.java:29)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at com.example.quality_of_life.MainActivity.onCreate(MainActivity.java:20)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.Activity.performCreate(Activity.java:5163)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
08-29 10:56:56.125: E/AndroidRuntime(6457):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
08-29 10:56:56.125: E/AndroidRuntime(6457):     ... 11 more
4

3 回答 3

0

我认为您的布局中缺少一些组件。制作许多屏幕尺寸,您必须确保所有控件都必须在所有布局中不存在。请检查您的代码。

于 2013-08-29T09:22:10.290 回答
0

I would post this in a comment but I do not have required reputation!

Firstly could you post the code that is identified by com.example.quality_of_life.MainActivity.addListenerOnButton(MainActivity.java:29). That is the line that is causing your grief and it will probably be apparent what the problem is. When you say that debug mode did not work, did you set a breakpoint in your code, at line 29 of MainActivity?

Are you following guidelines from the Android developer guide? http://developer.android.com/guide/practices/screens_support.html

Could you also post the skeleton of the /res folder of your project as that will probably contain some clues too.

于 2013-08-29T09:23:23.140 回答
0

问题是在我的不同布局中我使用了不同的按钮,我的主脚本正在调用一个不存在的按钮。所以,它崩溃了。问题已解决 bij 用 android:visibility="gone" 隐藏按钮。

谢谢大家的遮阳篷

于 2013-09-04T07:00:13.927 回答