我正在开发一个Android应用程序,我正在从我的另一个类2扩展我的类1,并且其他类2从片段扩展。当我尝试使用intent从类1调用其他类时,我得到错误。我还在Manifest文件中注册了新类。 名为抽象片段的第1类是:
public abstract class AbstractFragment extends Fragment implements IFragment {
/**
* Fragment title
*/
private String mTitle;
/**
* Enable or not the fragment
*/
protected boolean mEnable;
/**
* Setter for the field mTitle
*
* @param mTitle
* the mTitle to set
*/
public void setTitle(final String mTitle) {
this.mTitle = mTitle;
}
/**
* Setter for the field mEnable
*
* @param mEnable
* the mEnable to set
*/
public void setEnable(final boolean mEnable) {
this.mEnable = mEnable;
}
@Override
public String getTitle() {
return mTitle;
}
@Override
public boolean isEnable() {
return mEnable;
}
}
Class 2,其名称为CardDetailFragment:
public class CardDetailFragment extends AbstractFragment {
/**
* Card to display
*/
private EmvCard mCard;
/**
* Empty view
*/
private LinearLayout mEmptyView;
/**
* Card view
*/
private ScrollView mScrollView;
/**
* Card number
*/
private TextView mCardNumber;
/**
* Card validity
*/
private TextView mCardValidity;
/**
* Image view
*/
private ImageView mImageView;
/**
* Extended layout
*/
private TableLayout mExtendedLayout;
/**
* Method used to create a new instance of the fragment
*
* @param pCard
* EmvCard
* @param pTitle
* fragment title
* @return fragment
*/
Button pay;
public static IFragment newInstance(final EmvCard pCard, final String pTitle) {
CardDetailFragment ret = new CardDetailFragment();
ret.setEnable(true);
ret.setTitle(pTitle);
ret.setCard(pCard);
return ret;
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
return inflater.inflate(R.layout.card_detail, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
// Get views
mEmptyView = (LinearLayout) view.findViewById(R.id.emptyView);
mScrollView = (ScrollView) view.findViewById(R.id.card_detail);
mCardNumber = (TextView) view.findViewById(R.id.cardNumber);
mCardValidity = (TextView) view.findViewById(R.id.cardValidity);
mImageView = (ImageView) view.findViewById(R.id.type);
mExtendedLayout = (TableLayout) view.findViewById(R.id.extended_content);
// Set OCR-A typeface
ViewUtils.setTypeFace(EmvApplication.sTypeface, mCardNumber, mCardValidity);
pay=(Button)view.findViewById(R.id.button1);
pay.setBackgroundColor(Color.BLACK);
pay.setTextColor(Color.WHITE);
// Update content
updateContent();
pay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in = new Intent(getActivity(),CaptureSignature.class);
startActivity(in);
}
});
}
/**
* Method used to update card detail content
*/
private void updateContent() {
if (getActivity() != null) {
if (mCard != null) {
mEmptyView.setVisibility(View.GONE);
mScrollView.setVisibility(View.VISIBLE);
// Update content
mCardNumber.setText(CardUtils.formatCardNumber(mCard.getCardNumber(), mCard.getType()));
SimpleDateFormat format = new SimpleDateFormat("MM/yy", Locale.getDefault());
mCardValidity.setText(format.format(mCard.getExpireDate()));
mImageView.setImageResource(CardUtils.getResourceIdCardType(mCard.getType()));
// Extended card data
// Remove all existing view
mExtendedLayout.removeAllViews();
// Card holder name
if (mCard.getHolderName() != null && mCard.getHolderName().length() > 1) {
createRaw(getString(R.string.extended_card_holder_name), mCard.getHolderName());
}
// card AID
if (StringUtils.isNotEmpty(mCard.getAid())) {
createRaw(getString(R.string.extended_title_AID), CardUtils.formatAid(mCard.getAid()));
}
// Card Application label
if (StringUtils.isNotEmpty(mCard.getApplicationLabel())) {
createRaw(getString(R.string.extended_title_application_label), mCard.getApplicationLabel());
}
// Card type
if (mCard.getType() != null) {
createRaw(getString(R.string.extended_title_card_type), mCard.getType().getName());
}
// Pin try left
createRaw(getString(R.string.extended_title_pin_try), mCard.getLeftPinTry() + " "
+ getString(R.string.extended_title_times));
// Atr desc
if (mCard.getAtrDescription() != null && !mCard.getAtrDescription().isEmpty()) {
createRaw(getString(R.string.extended_title_possible_bank), StringUtils.join(mCard.getAtrDescription(), "\n"));
}
} else {
mEmptyView.setVisibility(View.VISIBLE);
mScrollView.setVisibility(View.GONE);
}
}
}
/**
* Method used to create a row in the section "Extended card detail"
*
* @param pKeyName
* key title
* @param pValue
* key value
*/
private void createRaw(final String pKeyName, final String pValue) {
View v = View.inflate(getActivity(), R.layout.tablelayout_raw, null);
TextView title = (TextView) v.findViewById(R.id.extended_raw_title);
title.setText(pKeyName);
TextView content = (TextView) v.findViewById(R.id.extended_raw_content);
content.setText(pValue);
mExtendedLayout.addView(v);
}
public void update(final EmvCard pCard) {
mCard = pCard;
updateContent();
}
/**
* Setter for the field mCard
*
* @param mCard
* the mCard to set
*/
public void setCard(final EmvCard mCard) {
this.mCard = mCard;
}
}
我试图调用的类名为CaptureSignature。 错误日志是:
08-24 09:10:50.761: E/AndroidRuntime(15732): FATAL EXCEPTION: main
08-24 09:10:50.761: E/AndroidRuntime(15732): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.github.devnied.emvnfccard/com.github.devnied.emvnfccard.fragment.viewPager.impl.CaptureSignature}; have you declared this activity in your AndroidManifest.xml?
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1635)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.Activity.startActivityForResult(Activity.java:3430)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.Activity.startActivityForResult(Activity.java:3391)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:840)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.Activity.startActivity(Activity.java:3626)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.Activity.startActivity(Activity.java:3594)
08-24 09:10:50.761: E/AndroidRuntime(15732): at com.github.devnied.emvnfccard.fragment.viewPager.impl.CardDetailFragment$1.onClick(CardDetailFragment.java:120)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.view.View.performClick(View.java:4354)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.view.View$PerformClick.run(View.java:17961)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.os.Handler.handleCallback(Handler.java:725)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.os.Handler.dispatchMessage(Handler.java:92)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.os.Looper.loop(Looper.java:137)
08-24 09:10:50.761: E/AndroidRuntime(15732): at android.app.ActivityThread.main(ActivityThread.java:5328)
08-24 09:10:50.761: E/AndroidRuntime(15732): at java.lang.reflect.Method.invokeNative(Native Method)
08-24 09:10:50.761: E/AndroidRuntime(15732): at java.lang.reflect.Method.invoke(Method.java:511)
08-24 09:10:50.761: E/AndroidRuntime(15732): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-24 09:10:50.761: E/AndroidRuntime(15732): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
08-24 09:10:50.761: E/AndroidRuntime(15732): at dalvik.system.NativeStart.main(Native Method)
清单文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.devnied.emvnfccard"
android:versionCode="12"
android:versionName="2.0.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:name="com.github.devnied.emvnfccard.EmvApplication"
android:alwaysRetainTaskState="true"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyTheme" >
<activity
android:name=".activity.first"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_list" />
</activity>
<activity android:name=".activity.HomeActivity"></activity>
<activity android:name=".activity.currencies"></activity>
<activity android:name=".activity.CaptureSignature"></activity>
</application>
</manifest>
答案 0 :(得分:0)
更改此
<activity android:name=".activity.CaptureSignature"></activity>
到这个
<activity android:name=".fragment.viewPager.impl.CaptureSignature"></activity>
或提供您的活动的完整路径
<activity android:name="com.github.devnied.emvnfccard.fragment.viewPager.impl.CaptureSignature"></activity>