gpt4 book ai didi

android - java.util.FormatFlagsConversionMismatchException : Conversion = s, 标志 =

转载 作者:行者123 更新时间:2023-12-04 23:55:33 28 4
gpt4 key购买 nike

请帮帮我!我发现我的 Activity 有问题我正在尝试通过将 %s 显示为来自...的详细信息(信息)来创建警报 Activity

我的 Activity

   mPreAlarm = getIntent().hasExtra(EXTRA_PRE_ALARM_FLAG) && getIntent().getBooleanExtra(EXTRA_PRE_ALARM_FLAG, true);
if (mPreAlarm) {
String formatString = "%2$tl:%2$tM %2$tp %1$s";
if (mSettings.getTimeFormatFor(0) == ReyTime.TIME_24) {
formatString = "%2$tk:%2$tM %1$s";
}
mReyerName.setText(String.format(formatString, mReyerNameString, now));
} else {
mReyerName.setText(getString(R.string.reyer_name_time, mReyerNameString));
}

mAlarmOff = (Button) findViewById(R.id.alarm_off);
mAlarmOff.setOnClickListener(this);

try {
playAlarm();
} catch (Exception e) {
Log.e("RingAlarmActivity", e.getMessage(), e);
}

//if(PermissionUtil.hasSelfPermission(this, Manifest.permission.READ_PHONE_STATE)) {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
//}

我的字符串在我的应用中

    <string name="rey_name_time">%s time.</string>

我的 LogCat,我发现了一个错误,我无法修复它

05-11 19:39:53.384 9007-9007/com.rey.kampret E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rey.kampret, PID: 9007
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rey.kampret/com.rey.kampret.kampret1.RingAlarmActivity}: java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags =
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags =
at java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4131)
at java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:3035)
at java.util.Formatter$FormatSpecifier.checkGeneral(Formatter.java:2993)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2764)
at java.util.Formatter$FormatSpecifierParser.<init>(Formatter.java:2591)
at java.util.Formatter.parse(Formatter.java:2524)
at java.util.Formatter.format(Formatter.java:2472)
at java.util.Formatter.format(Formatter.java:2426)
at java.lang.String.format(String.java:2670)
at android.content.res.Resources.getString(Resources.java:406)
at android.content.Context.getString(Context.java:492)
at com.rey.kampret.kampret1.RingAlarmActivity.onCreate(RingAlarmActivity.java:104)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6176) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) 

最佳答案

当您使用“字符串”时,您需要使用“%s”,例如:

private String responseUser(User user) {
return String.format("hello %s, your email %s and pass %s! (log: %s)",
user.getName(),
user.getEmail(),
user.getPass(),
user.result()
);
}

关于android - java.util.FormatFlagsConversionMismatchException : Conversion = s, 标志 =,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43916287/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com