當我嘗試編譯我的Android Studio中的項目,我得到以下錯誤:Android Studio中的錯誤:(386,38)錯誤:不兼容的類型:字符串不能轉換爲背景
Error:(386, 38) error: incompatible types: String cannot be converted to Context
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
錯誤指對存在於我的SummaryFragment.java
班線
stripe = new Stripe(Const.STRIPE_TOKEN);
:
package com.example.Fragments;
// Stripe imports
import com.stripe.android.Stripe;
import com.stripe.android.TokenCallback;
import com.stripe.android.exception.AuthenticationException;
import com.stripe.android.model.Card;
import com.stripe.android.model.Token;
// Non-Stripe imports omitted
/**
* A simple {@link Fragment} subclass.
*/
public class SummaryFragment extends Fragment implements
View.OnClickListener {
// Other fields and methods omitted
private void getStripeToken(String cardNo, String expMonth, String expYear, String cvv) {
loadingDialog.show();
Card card = new Card(cardNo, Integer.parseInt(expMonth), Integer.parseInt(expYear), cvv);
Stripe stripe = null;
try {
stripe = new Stripe(Const.STRIPE_TOKEN);
// Other logic omitted
} catch (AuthenticationException e) {
e.printStackTrace();
}
}
}
我是什麼做錯了?
非常感謝您爲格式化我的原始問題並使其更加智能化。當我嘗試你的建議時,我得到另一個錯誤:錯誤:(405,11)錯誤:異常AuthenticationException永遠不會在相應的try語句的主體中拋出。這個錯誤指向405行,這裏是405行:} catch(AuthenticationException e){ – geemint
不客氣!新的錯誤告訴你,相關的'try'塊中包含的代碼實際上都不會拋出類型爲'AuthenticationException'的Exception。您可能完全可以刪除catch塊。但是,如果這不起作用,請發佈一個包含相關代碼的小片段的新問題。由於此答案似乎已成功解決了原始問題,請將其標記爲已接受(綠色複選標記)。通過確保每個問題都專注於一個問題,我們會讓其他人更容易找到答案! – stkent