-1
在函數SetIntent中,我初始化了對象inputIntent,inputIntent和emailIntent都是相同的指針。
爲什麼obj emailIntent爲null並顯示「Error」?從 Utility.SetIntent(getApplicationContext(),emailIntent,myindex)方法爲什麼obj emailIntent爲空?
Intent emailIntent=null;
Utility.SetIntent(getApplicationContext(),emailIntent, myindex);
if (emailIntent==null){
Toast.makeText(getApplicationContext(),"Error" ,Toast.LENGTH_SHORT).show();
}
public static final String MyIntent=Intent.ACTION_SEND_MULTIPLE;
public static final String MySetType="image/*";
public static void SetIntent(Context mycontext, Intent inputIntent, int index) {
inputIntent = new Intent(MyIntent);
inputIntent.setType(MySetType);
PackageManager pm = mycontext.getPackageManager();
List<ResolveInfo> emailers = pm.queryIntentActivities(inputIntent, 0);
int dbIndex=index-1;
if (
((dbIndex)<= (emailers.size()-1))
&&
((dbIndex)>=0)
)
{
ResolveInfo r = emailers.get(dbIndex);
inputIntent.setClassName(r.activityInfo.packageName, r.activityInfo.name);
Toast.makeText(mycontext,r.activityInfo.packageName+" "+r.activityInfo.name ,Toast.LENGTH_SHORT).show();
}
}
嗯,你把它設置爲null,對吧? 'emailIntent = null;'? – g00dy
顯示您的完整代碼和日誌,請 – yushulx
我必須首先設置emailIntent = null,如果不是,我將得到錯誤 本地變量emailIntent可能未初始化\t!但是我調用了函數Utility.SetIntent來初始化emailIntent。 – HelloCW