Iam이 트위터의 공유 버튼을 설정하여 나중에 드로어 블에서 동적으로 변경할 수 있습니다.이 코드를 네트워크에서 가져 와서 앱에 붙여 넣습니다. 다음 오류가 발생했습니다. 널 포인터 예외 및 캔트 그것을 밖으로 그림 도움을 주셔서 감사합니다 감사합니다.ImageView에서 java null 포인터 예외가 발생했습니다
enter code here
ImageView twittersharing =(ImageView)findViewById(R.id.twitter_sharing);
twittersharing.setOnClickListener(new View.OnClickListener()
{
private Context context;
@Override
public void onClick(View arg0)
{
//Toast.makeText(getBaseContext(), "On click", Toast.LENGTH_SHORT).show();
// TODO Auto-generated method stub
File filePath = context.getFileStreamPath("placeholder.jpg");
share("com.twitter.android",filePath.toString());
}
});
public void share(String nameApp, String imagePath)
{
try
{
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpg");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty())
{
for (ResolveInfo info : resInfo)
{
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpg"); // put here your mime type
if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by ME");
targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)));
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
catch(Exception e)
{
Log.v("VM","Exception while sending image on" + nameApp + " "+ e.getMessage());
}
}
왜 그랬습니까? –
아마도 R 파일을 다시 빌드하기 위해 프로젝트를 청소 해보십시오. Project> clean –
로그 오류가 발생 했습니까? nullpointer는 어떤 행에서 발생합니까? –