我不明白为什么我得到臭名昭着的"IllegalStateException"与以下代码:
private void mergeQueryStrings(String url, Map parameterMap) {
String queryString = getQueryString(url);
if(queryString!=null){
String [] params = queryString.split("&");
for(String param:params){
parameterMap.put(param.split("=")[0], param.split("=")[1]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谁能开导我?
我有一个使用JSF 2.0.2在Glassfish服务器上运行的Java应用程序.
在JSF级别我有以下方法调用.
<h:commandLink action="#{printWB.doOpenVehicleToPrintInPDF}" target="_blank">Print</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
我的方法doOpenVehicleToPrintInPDF定义如下:
public String doOpenVehicleToPrintInPDF() {
FacesContext ctxt = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctxt.getExternalContext().getResponse();
try {
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=\"" + configUrl + ".pdf\"");
final ServletOutputStream stream = response.getOutputStream();
final VehiclePrintSummaryToPdf vehiclePrintPdf = new VehiclePrintSummaryToPdf(ctxt, summary);
vehiclePrintPdf.createPdfDocument(stream, summary);
stream.flush();
Validate.isTrue(response.isCommitted());
stream.close();
} catch (Exception ex) {
LOG.error("Error in PDF print processing!", ex);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
调用该方法,生成PDF(使用itext库),然后抛出下面的异常.我调试了这个,并且在返回null之后出现异常;
任何暗示这里有什么问题以及如何避免这种异常?
提前致谢.
java.lang.IllegalStateException
at org.apache.coyote.tomcat5.CoyoteResponseFacade.setBufferSize(CoyoteResponseFacade.java:260)
at com.sun.faces.context.ExternalContextImpl.setResponseBufferSize(ExternalContextImpl.java:795)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingSt
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.jav
at …Run Code Online (Sandbox Code Playgroud) 我遇到了这个问题,同时尝试自动装配一个可运行的类,并在不同的调用中创建它的不同实例并将其保存在一个数组中.
xml配置是:
<bean name="threadName" Class="ABC" scope="prototype" />
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我正在尝试这样的事情:
public class ThreadHandler{
@Autowired
private ABC threadName;
//getter
ABC getThreadName(){
return threadName;
}
public void someFunction(){
List<ABC> abc = new ArrayList(ABC>();
for (int i=0;i<SOME_CONST;i++){
ABC tName = getThreadName();
abc.add(tName);
tName.start();
}
}
Run Code Online (Sandbox Code Playgroud)
}
让我们ABC成为一个班级Thread/Runnable/Callable.
通过这种方式,它会抛出java.lang.IllegalThreadStateException.但是,如果我使用它,它的工作正常ABC tName =appContext.getBean("threadName",ABC.class);
为什么会这样?
在尝试从getMethod获取对象时,我们不会获得新实例吗?
我知道还有很多其他帖子处理同样的错误,但所有这些帖子要么是关于 JSP/GSP 页面的,要么是出于任何其他原因对我来说不是很有帮助。我正在使用带有 Thymeleaf 的 Spring MVC。以下函数用于下载文件。
@RequestMapping(value = "/test/download/*", method = RequestMethod.GET)
public String getFile(HttpServletResponse response)
{
ServletOutputStream stream = null;
try
{
stream = response.getOutputStream();
MultipartFile f = test.getFile();
InputStream is = f.getInputStream();
IOUtils.copy(is, stream);
response.flushBuffer();
stream.flush();
stream.close();
} catch(Exception ex)
{
}
return "test";
}
Run Code Online (Sandbox Code Playgroud)
它确实有效,所以问题不大,但在控制台中,我总是收到以下错误:
2014-01-10T09:28:09.053+0100 SEVERE Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause …Run Code Online (Sandbox Code Playgroud) 我正在尝试在删除按钮上使用警报对话框。但是显示对话框显示异常。当我单击删除时,它会崩溃并在 .show 上显示异常。
我尝试为此活动使用 Theme.AppCompat 主题,但它仍然崩溃。
<activity android:name=".AddEventActivity"
android:theme="@style/Theme.AppCompat">
</activity>
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(getApplicationContext())
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Yaay", Toast.LENGTH_SHORT).show();
i = new Intent();
db.deleteEvent(eventData);
Log.i("d", "delete");
setResult(RESULT_OK, i);
finish();
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show(); …Run Code Online (Sandbox Code Playgroud) java android android-appcompat android-theme illegalstateexception
我的应用程序使用PrintManager进行PDF打印.此功能在Android L和M中运行良好,但在Android N下失败.
在onOptionsItemSelected()的选项菜单中的非片段活动中调用打印操作.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
String jobName = "createPDFReport";
printManager.print(jobName, new InterimReportAdapter(AuditValidation.this, auditObject), new PrintAttributes.Builder().build());
}
Run Code Online (Sandbox Code Playgroud)
Android N抛出
FATAL EXCEPTION: ec.kat.kataudit, PID: 4052
java.lang.IllegalStateException: Can print only from an activity
at android.print.PrintManager.print(PrintManager.java:525)
at ec.kat.kataudit.AuditValidation.onOptionsItemSelected(AuditValidation.java:124)
at android.app.Activity.onMenuItemSelected(Activity.java:3204)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
...
Run Code Online (Sandbox Code Playgroud)
AuditValidation.java:124指向printManager.print()调用.
Activity扩展了android.support.v7.app.AppCompatActivity.编译目标版本为25,app正在使用最新的库(截至今天为25.3.1).
任何想法都非常感谢!
最好的祝福!
I'm starting an IntentService from MainActivity:onCreate and I noticed this crash from the crash reporting only on Android Oreo above:
java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.company.mobile/com.company.mobile.gcm.RegistrationIntentService }: app is in background uid UidRecord{c96fbae u0a184 TPSL idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon()(ContextImpl.java:1577)
at android.app.ContextImpl.startService()(ContextImpl.java:1532)
at android.content.ContextWrapper.startService()(ContextWrapper.java:664)
at cs.a()(FirebaseUtility.java:42)
at com.company.mobile.MainActivity.onCreate()(MainActivity.java:81)
at android.app.Activity.performCreate()(Activity.java:7136)
at android.app.Activity.performCreate()(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate()(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity()(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity()(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute()(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks()(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute()(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage()(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage()(Handler.java:106)
at android.os.Looper.loop()(Looper.java:193)
at android.app.ActivityThread.main()(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke()(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run()(RuntimeInit.java:493)
at …Run Code Online (Sandbox Code Playgroud) android illegalstateexception android-intentservice android-8.0-oreo
下面是抛出错误消息的代码
“ java.lang.illegal 状态异常:Fragment 必须是公共静态类才能从实例状态正确重新创建”
下面的代码片段只有在我**compile 'com.google.android.gms:play-services-ads:11.8.0'在 build.gradle 文件中包含**后才会抛出错误,否则工作正常。
public void selectDate(View view) {
DialogFragment newFragment = new SelectDateFragment();
newFragment.show(getFragmentManager(), "DatePicker");
}
@SuppressLint("ValidFragment")
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
Run Code Online (Sandbox Code Playgroud) 我正在获取一个加载对象,等待来自Web服务的请求。但是有时该对象导致我的应用程序结束。我无法准确检测出所涉及的错误。
为了防止发生此错误,我在传递活动时将对象称为“ dismiss”和“ cancel”,但这没有用。然后,我分配了“ null”值,该值也不起作用。我没有再工作,因为我以为我在跟Tag打交道。
我的错误代码;
2019-03-27 11:51:20.502 29685-29685/com.xxxx.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxxx.app, PID: 29685
java.lang.IllegalStateException: Fragment already added: DelayedProgressDialog{d8bd442 #1 Delaleyed}
at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManager.java:1916)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:765)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Run Code Online (Sandbox Code Playgroud)
我的使用进度对话框类;
public class DelayedProgressDialog extends DialogFragment {
private static final int DELAY_MILLISECOND = 450;
private static final int MINIMUM_SHOW_DURATION_MILLISECOND = 300;
private static final int PROGRESS_CONTENT_SIZE_DP = …Run Code Online (Sandbox Code Playgroud) android fragment illegalstateexception android-dialogfragment
在我的 Android 应用程序中,我使用Room本地数据库来存储用户的帐户信息。当我发出一个简单的Room请求来检索Account存储在数据库中的对象时,我收到以下错误消息:
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
Run Code Online (Sandbox Code Playgroud)
这是Fragment我发出本地数据库请求的代码:
// AccountInformationFragment.kt
accountDataFragmentViewModel.retrieveAccountData(accountId).observe(viewLifecycleOwner, Observer {
// do some stuff
})
Run Code Online (Sandbox Code Playgroud)
在ViewModel课堂上我是这样实现的retrieveAccountData():
// AccountInformationFragmentViewModel.kt
// used to get the account from the local datasource
fun retrieveAccountData(id:Long): LiveData<Account>{
val result = MutableLiveData<Account>()
viewModelScope.launch {
val account = authRepository.retrieveAccountData(id)
result.postValue(account)
}
return result
}
Run Code Online (Sandbox Code Playgroud)
在Repository …
android illegalstateexception android-room kotlin-coroutines
android ×6
java ×6
spring ×2
android-room ×1
autowired ×1
exception ×1
fragment ×1
jsf ×1
outputstream ×1