开发者

if something = false display ads

开发者 https://www.devze.com 2023-03-05 03:52 出处:网络
i have a protected boolean as follows protected boolean isKeyInstalled(Context context) { // the packagename of the \'key\' app

i have a protected boolean as follows

protected boolean isKeyInstalled(Context context) {
          // the packagename of the 'key' app
          String proPackage = "com.funhouse.mytimmieskey";

          // get the package manager
          final PackageManager pm = context.getPackageManager();

          // get a lis开发者_JAVA技巧t of installed packages
          List<PackageInfo> list = pm.getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS);

          // let's iterate through the list
          Iterator<PackageInfo> i = list.iterator();
          while(i.hasNext()) {
            PackageInfo p = i.next();
            // check if proPackage is in the list AND whether that package is signed
            //  with the same signature as THIS package
            if((p.packageName.equals(proPackage)) &&
               (pm.checkSignatures(context.getPackageName(), p.packageName) == PackageManager.SIGNATURE_MATCH))
              return true;
          }
          return false;
        }

I'm trying to get it to show ads if false

if(isKeyInstalled(null) != false){
            //AdMob Banner
            LinearLayout parent = (LinearLayout) findViewById(R.id.adveiw);
            AdView ad = new AdView(this, AdSize.BANNER, "a14db2c31f42ef0");
            parent.addView(ad);
            AdRequest r = new AdRequest();
            r.setTesting(false);
            ad.loadAd(r);
        }

i have no code errors but this keeps cashing my app.

here is logcat

05-11 00:18:37.253: INFO/ActivityManager(52): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.funhouse.mytimmies/.TimsMain bnds=[125,410][235,528] }
05-11 00:18:37.433: INFO/ActivityManager(52): Start proc com.funhouse.mytimmies for activity com.funhouse.mytimmies/.TimsMain: pid=1225 uid=10030 gids={3003}
05-11 00:18:37.814: DEBUG/ddm-heap(1225): Got feature list request
05-11 00:18:38.944: DEBUG/AndroidRuntime(1225): Shutting down VM
05-11 00:18:38.964: WARN/dalvikvm(1225): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-11 00:18:38.974: ERROR/AndroidRuntime(1225): Uncaught handler: thread main exiting due to uncaught exception
05-11 00:18:39.044: ERROR/AndroidRuntime(1225): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.funhouse.mytimmies/com.funhouse.mytimmies.TimsMain}: java.lang.NullPointerException
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.os.Looper.loop(Looper.java:123)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at java.lang.reflect.Method.invokeNative(Native Method)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at java.lang.reflect.Method.invoke(Method.java:521)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at dalvik.system.NativeStart.main(Native Method)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225): Caused by: java.lang.NullPointerException
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at com.funhouse.mytimmies.TimsMain.isKeyInstalled(TimsMain.java:76)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at com.funhouse.mytimmies.TimsMain.onCreate(TimsMain.java:27)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-11 00:18:39.044: ERROR/AndroidRuntime(1225):     ... 11 more
05-11 00:18:39.095: INFO/Process(52): Sending signal. PID: 1225 SIG: 3


I'm guessing final PackageManager pm = context.getPackageManager();is line 76 where your error is occuring, as the context you are passing is null...it's unable to start the Activity since the error is occuring in the onCreate method...pass in this (being your activity) as the context and it'll fix your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消