来自Android中另一个类的错误调用方法

时间:2018-08-10 14:05:27

标签: android nullpointerexception

我有一个课程(Get_Shared_Performance_Info_User_By_Telephone)和一个活动(Homepagee)。 我在活动中创建了以下方法。

    File rootPath = new File(Environment.getExternalStorageDirectory(), "Sapp");
    if(!rootPath.exists()) {
        rootPath.mkdir();
    }
    File rootPath2 = new File(Environment.getExternalStorageDirectory()+"/Sapp", ".Profile");
    if(!rootPath2.exists()) {
        rootPath2.mkdir();
    }
    File file2= new File(android.os.Environment.getExternalStorageDirectory()+ "/Sapp/.Profile/"+Global.TelePhone + ".jpg");
    CircleImageView  fab=(CircleImageView)findViewById(R.id.fab);
    if(file2.exists()) {
        Bitmap bmp = BitmapFactory.decodeFile(String.valueOf(file2));
        fab.setImageBitmap(bmp);
    }else{
        if (!Global.Picture.equals("")) {
            Glide
                    .with(Homepagee.this)
                    .load("http://192.168.175.1/Sapp/profile_pic/" +Global.TelePhone + ".jpg")
                    .into(fab);
        }else{
            Glide.with(Homepagee.this).load(R.drawable.blankimageforshoe).into(fab);
        }
    }
}

在该类中,我将该方法称为:

Homepagee callmethod=new Homepagee();
callmethod.Check_File_And_Folder_Path();

但是在运行程序时,会显示以下错误:

08-10 17:51:32.623 6562-6562/ir.mosayebtorabi.sapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: ir.mosayebtorabi.sapp, PID: 6562
                                                                 java.lang.NullPointerException
                                                                     at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:117)
                                                                     at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
                                                                     at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
                                                                     at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
                                                                     at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202)
                                                                     at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
                                                                     at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                                     at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                                                                     at ir.mosayebtorabi.sapp.Homepagee.sssss(Homepagee.java:301)
                                                                     at ir.mosayebtorabi.sapp.Get_Shared_Performance_Info_User_By_Telephone$1.onResponse(Get_Shared_Performance_Info_User_By_Telephone.java:103)
                                                                     at ir.mosayebtorabi.sapp.Get_Shared_Performance_Info_User_By_Telephone$1.onResponse(Get_Shared_Performance_Info_User_By_Telephone.java:40)
                                                                     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
                                                                     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
                                                                     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
                                                                     at android.os.Handler.handleCallback(Handler.java:733)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                     at android.os.Looper.loop(Looper.java:136)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5019)
                                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                                                                     at dalvik.system.NativeStart.main(Native Method)

Debug引用此代码:

CircleImageView  fab=(CircleImageView)findViewById(R.id.fab);

救救我。

1 个答案:

答案 0 :(得分:0)

  

Homepagee callmethod = new Homepagee();   callmethod.Check_File_And_Folder_Path();

这不是实例化Activity的方法。看看第一本应用指南:https://developer.android.com/training/basics/firstapp/starting-activity