我试图从一个片段中调用一个活动,但是当我在手机中运行它时应用程序停止了。如果我删除意图,它会显示 toast,但是当我尝试使用意图运行它时,它会停止。
我已经将活动添加到清单中。
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;
}
}