问题列表 - 第46981页

Combobox示例

我为foreach收到以下错误

Foreach语句不能对'object'类型的变量进行操作,因为'object'不包含'GetEnumerator'的公共定义

我正在进行任何语法错误

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Namepopu_SelectedIndexChanged(object sender, EventArgs e)
        {
            // this.textBox1.Text = Namepopu.Text;
           // this.textBox1.Text = " ";

            foreach (int i in Namepopu.SelectedItem)
                this.textBox1.Text += Namepopu.Text[i];
            {

            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
1227
查看次数

推荐用于Delphi桌面游戏的2D Sprite引擎?

对于Delphi精灵引擎,我应该考虑哪些选择.

我知道

  • GLScene中
  • 安道尔2D

还有什么我想念的?

最好是依赖于OpenGL.DirectX唯一的解决方案不是很受欢迎.

delphi opengl sprite

11
推荐指数
1
解决办法
3604
查看次数

提高PostgreSQL聚合性能

在PostgreSQL中执行MAX(id)聚合的提高查询速度的最佳方法是什么?

我有一个与id相关的适度数量的记录,我可以在一秒内COUNT()例如

select count(id) as cnt from mytable where ref_id=2660

row   cnt
1     2844
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用MAX()查找最新的记录ID时,查询需要将近5分钟.

select max(id) as id from mytable where ref_id=2660
Run Code Online (Sandbox Code Playgroud)

这是令人惊讶的,因为我已经发现PG出乎意料地快得多,查询复杂得多.为什么查询时间会有这么大的差异,特别是对于这么少的记录?什么是改善这种表现的最佳方法?

编辑:这是上面MAX()选择的查询计划:

"Result  (cost=219.84..219.85 rows=1 width=0)"
"  InitPlan 1 (returns $0)"
"    ->  Limit  (cost=0.00..219.84 rows=1 width=4)"
"          ->  Index Scan Backward using mytable_pkey on mytable  (cost=0.00..773828.42 rows=3520 width=4)"
"                Filter: ((id IS NOT NULL) AND (ref_id = 2660))"
Run Code Online (Sandbox Code Playgroud)

sql database postgresql

6
推荐指数
1
解决办法
4262
查看次数

ByteBuffer不释放内存

在Android上,直接ByteBuffer似乎永远不会释放其内存,即使在调用System.gc()时也是如此.

示例:做

Log.v("?", Long.toString(Debug.getNativeHeapAllocatedSize()));
ByteBuffer buffer = allocateDirect(LARGE_NUMBER);
buffer=null;
System.gc();
Log.v("?", Long.toString(Debug.getNativeHeapAllocatedSize()));
Run Code Online (Sandbox Code Playgroud)

在日志中给出两个数字,第二个数字至少比第一个大LARGE_NUMBER.

我如何摆脱这种泄漏?


添加:

按照Gregory的建议来处理C++方面的alloc/free,然后我定义了

JNIEXPORT jobject JNICALL Java_com_foo_bar_allocNative(JNIEnv* env, jlong size)
    {
    void* buffer = malloc(size);
    jobject directBuffer = env->NewDirectByteBuffer(buffer, size);
    jobject globalRef = env->NewGlobalRef(directBuffer);
    return globalRef;
    }

JNIEXPORT void JNICALL Java_com_foo_bar_freeNative(JNIEnv* env, jobject globalRef)
    {
    void *buffer = env->GetDirectBufferAddress(globalRef);
    free(buffer);
    env->DeleteGlobalRef(globalRef);
    }
Run Code Online (Sandbox Code Playgroud)

然后我在JAVA端获得我的ByteBuffer

ByteBuffer myBuf = allocNative(LARGE_NUMBER);
Run Code Online (Sandbox Code Playgroud)

并释放它

freeNative(myBuf);
Run Code Online (Sandbox Code Playgroud)

不幸的是,虽然它确实分配好了,但它仍然保持根据Debug.getNativeHeapAllocatedSize()和b)分配的内存导致错误

W/dalvikvm(26733): JNI: DeleteGlobalRef(0x462b05a0) failed to find entry (valid=1)
Run Code Online (Sandbox Code Playgroud)

我现在彻底搞糊涂了,我以为我至少理解了C++方面的事情......为什么free()没有返回内存?我做错了DeleteGlobalRef()什么?

java-native-interface android memory-leaks bytebuffer

9
推荐指数
1
解决办法
2万
查看次数

使用@Inject将无状态EJB注入CDI Weld ManagedBean(jboss 6 AS上的JSF 1.2 EJB应用程序)

目前我正在尝试将无状态EJB注入到Jboss 6 AS Final上的CDI管理控制器中.控制器在上下文中管理,可从JSF页面访问.如果我注入无状态bean @EJB正在工作.如果我注入无状态EJB,@Inject我会得到以下异常:

我的控制器:

@Named("TestController")
public class TestController {   
    @Inject
    private TestManagerLocal myTestManager;
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我的无状态豆:

@SuppressWarnings("unchecked")
@Stateless
public class TestManagerBean implements TestManagerLocal {

    @PersistenceContext
    private EntityManager em;
        ...
}
Run Code Online (Sandbox Code Playgroud)

Bean的接口使用@Local注释.

如果我尝试调用myTestManager,我会得到以下异常:

WELD-000079在JNDI中找不到EJB:class de.crud.org $ jboss $ weld $ bean-jboss $ classloader:id ="vfs:$$$ usr $ local $ jboss $ server $ default $ deploy $ test $耳朵"-SessionBean-TestManagerBean _ $$ _ WeldProxy

多谢.

dependency-injection cdi ejb-3.1 jboss-weld

6
推荐指数
2
解决办法
2万
查看次数

persistence.xml - spring JPA

我已经阅读了几十篇文章,但我无法弄清楚,错误在哪里......它应该非常简单.我正在尝试使用Spring和JPA在appengine上编写应用程序.

我正在使用JEE5项目(不知道是否重要)

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="persistenceXmlLocation">
        <value>classpath*:/META-INF/persistence.xml</value>
    </property>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="transactions-optional" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
Run Code Online (Sandbox Code Playgroud)

persistence.xml文件位于META-INF目录(ROOT/META-INF/persistence.xml)

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

    <persistence-unit name="transactions-optional">
        <provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
        </properties>
    </persistence-unit>

</persistence>
Run Code Online (Sandbox Code Playgroud)

我仍然得到这个异常(我试图在src目录中移动meta-inf目录没有成功,异常是相同的)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericJpaDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: …
Run Code Online (Sandbox Code Playgroud)

google-app-engine spring jpa

7
推荐指数
1
解决办法
5720
查看次数

为什么垃圾收集不适用于线程?

在我的应用程序中,每个东西都可以正常工作,直到我分离一个线程从文件中读取音频数据并进行处理.

无论我做什么,垃圾收集似乎都不知道这个线程上发生了什么.我试过[NSThread self],[NSThread currentThread],[[NSGarbageCollector defaultCollector] collectIfNeeded]和collectExhaustivly].我从NSThread转到NSOperation与NSOperationQueue.

这些建议的解决方案都没有奏效.最近,我从NSMutableArrays切换到

Float32* pfArray= calloc(numFloats, sizeof(Float32));

保存我的数据,并用来 free(pfArray); 释放那个记忆.这样做效果更好,但仍然泄漏了不错的数量.

在Activity Monitor中指示的"真实内存"遇到一些任意数字后,垃圾收集似乎开始工作到一定程度,但是当它确实起作用时,它并不释放所有正在使用的内存.它只是不会让它远高于任意阈值.

我已经读过GC是要走的路,但现在我不确定并且有一个几乎完全编写的程序.任何建议都会非常有帮助.谢谢!

cocoa garbage-collection objective-c nsoperation

0
推荐指数
1
解决办法
391
查看次数

如何测试文件系统操作

我有一个同步两个文件夹的方法,如下所示:

void Synchronize(string folderAPath, string folderBPath)
{
    //Code to synchronize the folders
}
Run Code Online (Sandbox Code Playgroud)

测试文件是否正确同步的最佳方法是什么,或者通常是测试操作文件系统的测试方法?有没有办法设置虚拟文件夹?

.net c# testing unit-testing

6
推荐指数
2
解决办法
1121
查看次数

切换空间时保持窗口在顶部

我创建了一个窗口使用-[NSWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces].
它只做我想要的一半,但是:当我切换空格时,窗口也会切换空格(如预期的那样),但我的窗口移动到该空间中所有其他窗口后面的后面.这特别糟糕,因为我的应用程序处于活动状态,但其窗口低于所有其他应用程序的窗口.我尝试将级别更改为NSFloatingWindowLevel,这确实保持在顶部,但是当切换空格时它会丢失键状态(焦点).

我尝试NSWindowCollectionBehaviorMoveToActiveSpace了收集行为,但它绝对不是我想要的.

有希望吗?我知道几乎没有其他与Spaces相关的API.

macos cocoa mission-control

5
推荐指数
1
解决办法
1823
查看次数

子进程之间的UNIX管道

我正在尝试编写一个程序,它将在它们之间产生任意数量的子进程和管道,类似于命令行管道.在我的情况下,我正在尝试"ls -l | more"并将其输出到stdout,然后让父级继续执行更多命令.

我将以下代码作为最小示例:

int main (int argc, const char * argv[]) {
    int fd[2];
    pipe(fd); 
    chdir("/directory/with/lots/of/files");

    // Create one child process for more
    int pid = fork();
    if (pid == 0) {
        close(fd[1]);
        int ret = dup2(fd[0],0);
        if (ret < 0) perror("dup2");
        char *argv[10];
        argv[0] = "more";  argv[1] = NULL;
        execvp("more", argv);
    } 
    // Create another child process for ls
    int pid2 = fork();
    if (pid2 == 0) {
        int ret = dup2(fd[1],1);
        if (ret < 0) perror("dup2"); …
Run Code Online (Sandbox Code Playgroud)

c shell pipe process exec

7
推荐指数
1
解决办法
2万
查看次数