java.util.FormatFlagsConversionMismatchException:Conversion = s,Flags =

时间:2017-05-11 13:03:11

标签: android

请帮帮我! 我发现我的活动有问题 我试图通过显示%s作为详细信息(信息)来创建一个警报活动。

我的活动

   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) 

1 个答案:

答案 0 :(得分:2)

使用“字符串”时,需要使用“%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()
                );
    }