错误而在Android中使用PackageManager [英] Error while using PackageManager in Android

查看:133
本文介绍了错误而在Android中使用PackageManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Android应用程序,我在工作中的问题中,我得到的错误,当我使用PackageManager。

I got a problem in one Android Application which I am working in which I am getting error when I use PackageManager.

中的应用是如下:

package com.main.home;

public class Home extends Activity
{
    //onclicking a Button say "send"
    send.onClickListener() 
    {
        public void onClick() {
            Intent i =new Intent();
            i.setClassName("com.main.home", "com.main.home.home1");
            startActivity(i); 
    }
}

Home1.java

package com.main.home;

import com.andr.resulting.Result ;

public class Home1 extends Activity  {
    EditText et=(EditText)findViewById(R.id.e1);
    //Clicking on forwardButton in that onClick()

    public void onClick()
    {
        String s[] = {e1.getText().toString(),""};
        //Calling a method in a class Result of another package which is not activity
        Result.finalfunc(Home1.this,s);

}

Result.java

package com.andr.resulting;   //different package

public class Result {
    public static void finalfunc(Activity act,String[] re) ...
    //Here I want to get the details of this particular class's package (com.andr.resulting) using PackageManager

    // I tried like this:
    Result.this.getPackageManager().getApplicationInfo(Result.getPackageName(),0))

我收到错误 getPackageManager()不存在此类文件。

我要如何解决这个问题?我会热切地等待宝贵的答复。 在此先感谢。

How do I solve this issue? I will be eagerly waiting for valuable reply. Thanks in Advance.

推荐答案

结果没有延伸的上下文的喜欢你的Activity类一样。因此该方法不是在该类可用。你需要调用 act.getPackageManager()里面有代替 this.getPackageManager()

Result doesn't extend Context like your Activity class does. So the method isn't available in that class. You need to call act.getPackageManager() inside there instead of this.getPackageManager().

这篇关于错误而在Android中使用PackageManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆