-1

Activity (AndroidManifest で宣言) を開始するのに疲れましたが、そのエラーが表示されました:

08-11 16:04:05.952: E/AndroidRuntime(815): FATAL EXCEPTION: main
08-11 16:04:05.952: E/AndroidRuntime(815): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.radzik.devadmin/com.radzik.devadmin.MainActivity}: java.lang.NullPointerException
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.os.Looper.loop(Looper.java:137)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.ActivityThread.main(ActivityThread.java:4745)
08-11 16:04:05.952: E/AndroidRuntime(815):  at java.lang.reflect.Method.invokeNative(Native Method)
08-11 16:04:05.952: E/AndroidRuntime(815):  at java.lang.reflect.Method.invoke(Method.java:511)
08-11 16:04:05.952: E/AndroidRuntime(815):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-11 16:04:05.952: E/AndroidRuntime(815):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-11 16:04:05.952: E/AndroidRuntime(815):  at dalvik.system.NativeStart.main(Native Method)
08-11 16:04:05.952: E/AndroidRuntime(815): Caused by: java.lang.NullPointerException
08-11 16:04:05.952: E/AndroidRuntime(815):  at com.radzik.devadmin.MainActivity.ustawWidokMain(MainActivity.java:107)
08-11 16:04:05.952: E/AndroidRuntime(815):  at com.radzik.devadmin.MainActivity.onCreate(MainActivity.java:35)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.Activity.performCreate(Activity.java:5008)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-11 16:04:05.952: E/AndroidRuntime(815):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-11 16:04:05.952: E/AndroidRuntime(815):  ... 11 more

これは、エラーが 107 行目にあることを意味します。

private void ustawWidokMain()
{
    setContentView(R.layout.activity_main);
    Button b01 = (Button)findViewById(R.id.main_pass);
    Button b02 = (Button)findViewById(R.id.main_wipes);
    Button b03 = (Button)findViewById(R.id.main_camera);
    Button b04 = (Button)findViewById(R.id.main_enctpyion);
    Button b05 = (Button)findViewById(R.id.main_b1);
    if(!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) && !pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) // there's error
    {
        b03.setEnabled(false);
    }

なぜそのエラーが発生するのかわかりません。そのメソッドは次のように呼び出されます。

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /* Some code has been removed */
        if(dcm.isAdminActive(c))
        ustawWidokMain();
4

3 に答える 3