我想从一个片段调用一个活动,但是当我在手机中运行应用程序时,应用程序会停止。如果我删除了意图,它会显示吐司,但是当我试图用意图运行时,它会停止。当试图打开一个活动时,应用程序停止
我已将活动添加到清单。
package com.example.bar.adapter;
import com.example.bar.R;
import com.example.bar.zbarreader.CameraTestActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
public class Inventory extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
//inflate the right layout
View rootView = inflater.inflate(R.layout.inventory, container, false);
// Define and execute a button
Button InvScan = (Button) rootView.findViewById(R.id.InvScan);
InvScan.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Show a toast
Toast.makeText(getActivity(), "Openning the Barcode Reader", Toast.LENGTH_SHORT).show();
// Call the Activity
Intent IntentScanner = new Intent(getActivity(), CameraTestActivity.class);
Log.i(getTag(), getTag());
startActivity(IntentScanner);
}
});
return rootView;
}
}
还添加logcat的[R有问题的结果。还请确保您已在AndroidManifest.xml中添加CameraTestActivity活动 –
显示您的“getTag()”方法。 –
粘贴你得到的异常的堆栈跟踪。答案很可能在某处。 – keno