我有附加文件列表,并想让我的LinearLayout与它水平滚动.我只将一个子LinearLayout添加到我的HorizontalScrollView,除了我得到IllegalStateException.我的xml:
<HorizontalScrollView
android:id="@+id/scrollMessageFiles"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:layout_below="@+id/editMessage"
android:orientation="horizontal"
android:weightSum="1.0" >
<LinearLayout
android:id="@+id/panelMessageFiles"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFFFFF"
>
</LinearLayout>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)
并希望将文件列表添加到ScrollView中的LinearLayout,如下所示:
public void addFiles()
{
HorizontalScrollView scroll = (HorizontalScrollView) findViewById(R.id.scrollMessageFiles);
LinearLayout layout = (LinearLayout) findViewById(R.id.panelMessageFiles);
if(!FileManagerActivity.getFinalAttachFiles().isEmpty())
{
for (File file: FileManagerActivity.getFinalAttachFiles())
{
View line = new View(this);
line.setLayoutParams(new LayoutParams(1, LayoutParams.MATCH_PARENT));
line.setBackgroundColor(0xAA345556);
informationView = new TextView(this);
informationView.setTextColor(Color.BLACK);
informationView.setTextSize(12);
informationView.setCompoundDrawablesWithIntrinsicBounds(
0, R.drawable.file_icon, 0, 0);
informationView.setText(file.getName().toString());
layout.addView(informationView, 0);
layout.addView(line, 1);
}
scroll.addView(layout);
}
}
Run Code Online (Sandbox Code Playgroud)
除了get之外,我只向HorizontalScrollView添加一个LinearLayout
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assignmentexpert/com.assignmentexpert.NewMessageActivity}: java.lang.IllegalStateException: …Run Code Online (Sandbox Code Playgroud) android textview horizontalscrollview android-linearlayout illegalstateexception
我正在为GoogleMaps V2创建MarkerDemo的自定义实现.我有一个奇怪的错误,我将LatLng值提供给LatLngBounds.Builder实例,然后将其作为变量传递给.build.当我通过Eclipse在调试模式下运行应用程序时,Map会加载.当我通过Eclipse正常运行时,会抛出一个带有"no included points"的IllegalStateException作为消息.有人可以帮忙吗?
这是一些协助的代码.
public class MyActivity extends android.support.v4.app.FragmentActivity
implements OnMarkerClickListener, OnInfoWindowClickListener,
OnMarkerDragListener {
private HashMap<DataItem, ArrayList<DataItem>> mUserLocations = new
HashMap<DataItem, ArrayList<DataItem>>();
private ArrayList<DataItem> mFeedData;
private NetworkingHandler mHandler = new NetworkingHandler("tag");
private GoogleMap mMap;
private final String DOWNLOAD_USER_LOCATIONS_URL =
"http://www.myfeedurllocation.com/page.php";
@Override
public void onCreate(Bundle savedBundleInstance) {
super.onCreate(savedBundleInstance);
setContentView(R.layout.activity_myactivitylayout);
downloadUserLocations();
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map. …Run Code Online (Sandbox Code Playgroud) java android android-sdk-2.3 illegalstateexception google-maps-android-api-2
道歉这是一个相当长的帖子,让我先尝试解释一下背景:
我已经阅读了很多关于这个主题的帖子(以及Alex关于这个主题的优秀博客文章),一般的结论似乎不是在异步回调中执行片段事务(参见Dianne的帖子),比如AsyncTask#onPostExecute().
但是我有2个案例需要这样做:
一个Activity示出的登录Fragment,当用户按下登录按钮,一个AsyncTask开始于服务器进行认证,则返回登录成功那么当,登录Fragment被替换为主要的应用程序Fragment.
一个Activity示出了主要的应用程序片段,当使用者触发,需要登录一些动作,登录片段替换被添加到堆栈中的主要片段.再次按下登录按钮时,AsyncTask使用服务器进行身份验证,然后当登录成功时,我们要弹出backstack以Fragment向用户显示主要内容并让他们执行他们想要执行的操作.
案例1可以通过使用来解决commitAllowingStateLoss,但案例2很棘手,因为没有这种风格的popBackStack FragmentManager.
在任何情况下,这两种情况都需要特殊处理应用程序进入后台AsyncTask#doInBackground(),导致onPostExecute()应用程序在后台时被调用.一种解决方案是使用Fragment.isResumed来保护替换片段或pop backstack,然后通过再次登录来处理进程被杀死的情况,或者保存一些指示成功的最近登录的标志并在应用程序恢复状态下替换/弹出登录片段(登录Fragment已恢复到顶部FragmentManager).或者允许状态丢失,并处理进程终止然后恢复的情况,检查最近登录并删除登录片段.
这是你如何处理这个?感觉就像处理一个非常常见的情况需要做很多工作.
android illegalstateexception android-fragments android-activity
我使用自定义JComboBox作为JTable中的单元格编辑器.当用户使用键盘控件进入单元格时,它会尝试打开弹出窗口.这会导致以下错误:
java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1964)
at java.awt.Component.getLocationOnScreen(Component.java:1938)
at javax.swing.JPopupMenu.show(JPopupMenu.java:887)
at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:191)
at javax.swing.plaf.basic.BasicComboBoxUI.setPopupVisible(BasicComboBoxUI.java:859)
at javax.swing.JComboBox.setPopupVisible(JComboBox.java:796)
Run Code Online (Sandbox Code Playgroud)
我看过一些文章说这是一个已知问题,解决方法是设置:
comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
Run Code Online (Sandbox Code Playgroud)
但这并没有帮助.无论如何这应该做什么?
我读过的关于这个的所有主题和文章对于问题的本质都非常模糊.
有没有人对这个问题出现的原因有什么了解?我的组合框是非常自定义的,所以它有助于理解问题的基础,所以我可以修复代码.
这是在捕获的组合框上的焦点获取事件上触发并调用setPopupVisible(true);
public void focusGained(java.awt.event.FocusEvent e)
{
//if focus is gained then make sure we show the popup if it is suppose to be visible
setPopupVisible(true);
//and highlight the selected text if any
comboTextEditor.setCaretPosition(comboTextEditor.getText().length());
comboTextEditor.moveCaretPosition(0);
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我在Java 1.7_40中获得与Java 1.6_45相同的结果
完整堆栈跟踪:
Exception in thread "AWT-EventQueue-1" java.awt.IllegalComponentStateException: component must be showing on …Run Code Online (Sandbox Code Playgroud) 运行我的Web应用程序时,每隔一次尝试,我都会得到下面列出的stacktrace。请注意,据我所知,在web.xml中似乎没有多个ContextLoader定义。此外,该应用在第二/第四/等位置运行良好。时间。与根本不起作用相比,此行为很难调试。谁能对此有所启发?
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:299)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4795)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1703)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud) 我有一个返回图像的servlet InputStreamResource.根据一些get query参数,大约有50个静态图像要返回.
因为每次请求时都不必查找每个图像(通常是这样),我想缓存那些图像响应.
@RestController
public class MyRestController {
//code is just example; may be any number of parameters
@RequestMapping("/{code}")
@Cachable("code.cache")
public ResponseEntity<InputStreamResource> getCodeLogo(@PathVariable("code") String code) {
FileSystemResource file = new FileSystemResource("d:/images/" + code + ".jpg");
return ResponseEntity.ok()
.contentType("image/jpg")
.lastModified(file.lastModified())
.contentLength(file.contentLength())
.body(new InputStreamResource(file.getInputStream()));
}
}
Run Code Online (Sandbox Code Playgroud)
使用@Cacheable注释时(无论是直接在RestMapping方法上还是重构到外部服务),我都得到以下异常:
cause: java.lang.IllegalStateException: InputStream has already been read - do not use InputStreamResource if a stream needs to be read multiple times - error: InputStream has already been …Run Code Online (Sandbox Code Playgroud) resources spring inputstream spring-mvc illegalstateexception
我的这个应用程序有点问题!这段代码:
package com.project.alpha_droid;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Bitmap img;
ImageView imagew;
void fill(int x, int y, int c){
if(img.getPixel(x,y)!=c){
img.setPixel(x,y,c);
if(img.getPixel(x+1,y)!=c){
fill(x+1,y,c);
}
if(img.getPixel(x,y+1)!=c){
fill(x,y+1,c);
}
if(img.getPixel(x-1,y)!=c){
fill(x-1,y,c);
}
if(img.getPixel(x,y-1)!=c){
fill(x,y-1,c);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imagew = (ImageView) findViewById(R.id.drawing);
imagew.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("Location", event.getX() + "x" + …Run Code Online (Sandbox Code Playgroud) 我有一个这样的模式“提名?奥斯卡”或“提名 2 座金球奖。提名?奥斯卡。30 次赢得 18 项提名” 我想确定 ? 用正则表达式,所以奥斯卡的数量。
好像有
对应这个问题:在java中提取两个字符串之间的字符串和
如何在两个字符串之间找到一个值?我试过这种模式:
final Pattern pattern = Pattern.compile("for(.*?)Oscar");
Run Code Online (Sandbox Code Playgroud)
接下来我尝试了这个问题:Java - 在两个字符串之间获取所有字符串的最佳方法?(正则表达式?)
final Pattern pattern = Pattern.compile(Pattern.quote("Nom") +"(.*?)"+ Pattern.quote("Oscar"));
Run Code Online (Sandbox Code Playgroud)
我的其余代码:
final Matcher matcher = pattern.matcher("Nom for 3 Oscar");
while(matcher.find()){
}
Log.d("Test", matcher.group(1));
Run Code Online (Sandbox Code Playgroud)
所有这些模式都会导致此异常:
java.lang.IllegalStateException:到目前为止没有成功的匹配
我想我只是监督一些非常简单的事情。
你们能帮帮我吗?
所以问题是我在循环后调用 matcher.group(1) 。我误解了 find 方法的工作原理。然而,当我在循环内调用 matcher.group(1) 时,这段代码确实有效。
final Pattern pattern = Pattern.compile("for(.*?)Oscar");
final Matcher matcher = pattern.matcher("Nom for 3 Oscar");
while(matcher.find()){
Log.d("Test", matcher.group(1));
}
Run Code Online (Sandbox Code Playgroud) 具有以下依赖性:
dependencies {
implementation "androidx.work:work-runtime:2.0.1"
androidTestImplementation "androidx.work:work-testing:2.0.1"
}
Run Code Online (Sandbox Code Playgroud)
当第二次运行此代码时:
Configuration config = new Configuration.Builder().build();
WorkManager.initialize(getApplicationContext(), config);
this.workManager = WorkManager.getInstance();
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
java.lang.IllegalStateException: WorkManager is already initialized.
Did you try to initialize it manually without disabling WorkManagerInitializer?
See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
Run Code Online (Sandbox Code Playgroud)
并且还会在本机端引发分段错误:
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR),
fault addr 0x878 in tid 10892 (ova.workmanager),
pid 10892 (ova.workmanager)
Run Code Online (Sandbox Code Playgroud)
这将是文档的WorkManager#initialize(Context, Configuration)。
目的是防止在手动初始化期间崩溃(以更改日志级别)。如何禁用WorkManagerInitializer?如果可能的话,我不想使用static关键字。
java android illegalstateexception android-workmanager androidx
一般来说,我对 Webflux 和 Spring 很陌生,并且在设置处理 POST 请求的简单服务器时遇到了麻烦:
WebfluxtestApplication.java
package com.test.webfluxtest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@SpringBootApplication
@RestController
public class WebfluxtestApplication {
public static void main(String[] args) {
SpringApplication.run(WebfluxtestApplication.class, args);
}
@PostMapping
public Mono<Person> processPerson(@RequestBody Mono<Person> personMono){
Person person = personMono.block();
person.setAge(42);
return Mono.just(person);
}
}
Run Code Online (Sandbox Code Playgroud)
如下Person:
人.java
package com.test.webfluxtest;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Person {
private String name;
private int age;
public Person(@JsonProperty String name, @JsonProperty int age){
this.name = name; …Run Code Online (Sandbox Code Playgroud) android ×6
java ×5
spring ×3
androidx ×1
inputstream ×1
jcombobox ×1
jtable ×1
regex ×1
resources ×1
spring-boot ×1
spring-mvc ×1
string ×1
swing ×1
textview ×1