我需要在Array中添加一个指定位置和值的元素.例如,我有阵列
int []a = {1, 2, 3, 4, 5, 6};
Run Code Online (Sandbox Code Playgroud)
应用后addPos(int 4, int 87)应该是
int []a = {1, 2, 3, 4, 87, 5};
Run Code Online (Sandbox Code Playgroud)
我知道这里应该是Array索引的转换,但是看不到如何在代码中实现它.
要从数据库中获取数据,我CursorLoader在应用程序中使用.一旦onLoadFinished()回调方法调用app的逻辑,就将Cursor对象转换为List业务模型需求中的对象.如果有大量数据,那么转换(繁重操作)需要一些时间.这会降低UI线程的速度.我尝试Thread使用RxJava2传递Cursor对象在非UI中启动转换,但得到Exception:
Caused by: android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method.
Run Code Online (Sandbox Code Playgroud)
这是Fragment代码的一部分:
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
QueryBuilder builder;
switch (id) {
case Constants.FIELDS_QUERY_TOKEN:
builder = QueryBuilderFacade.getFieldsQB(activity);
return new QueryCursorLoader(activity, builder);
default:
return null;
}
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
if (cursor.getCount() > 0) {
getFieldsObservable(cursor) …Run Code Online (Sandbox Code Playgroud) 嗨,
我正在尝试启动JBoss示例应用程序'jboss-as-helloworld'.得到了这样的例外:
16:23:51,118 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) Starting deployment of "jboss-as-helloworld.war"
16:23:51,176 INFO [org.jboss.weld] (MSC service thread 1-5) Processing CDI deployment: jboss-as-helloworld.war
16:23:51,178 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.unit."jboss-as-helloworld.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."jboss-as-helloworld.war".INSTALL: Failed to process phase INSTALL of deployment "jboss-as-helloworld.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_02]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_02]
at java.lang.Thread.run(Thread.java:722) [:1.7.0_02]
Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.naming.context.java.app.jboss-as-helloworld is already registered
at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154)
at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:226)
at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:560)
at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Hibernate和Maven开始项目.
我有这样的例外:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2176)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2157)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at FirstHibernate.com.myhib.CRUDS.CrudsOps.main(CrudsOps.java:15)
Run Code Online (Sandbox Code Playgroud)
这是我的项目结构的截图,(hibernate.cfg.xml在src /中):http: //imageshack.us/photo/my-images/692/screenshotxba.jpg/
CrudsOps.java
package FirstHibernate.com.myhib.CRUDS;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class CrudsOps {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SessionFactory sf = new Configuration().configure().buildSessionFactory();
System.out.println("Cfg and …Run Code Online (Sandbox Code Playgroud) 嗨,
我创建了我的TableModel,并希望在添加新行后刷新JTable.应该添加什么来监听"刷新"JTable?
public class MyTableModel implements TableModel {
private Set<TableModelListener> listeners = new HashSet<TableModelListener>();
//List<Staff> staffs = Factory.getInstance().getStaffDAO().getAllStaff();
private List<Staff> staffs;
public MyTableModel(List<Staff> staffs){
this.staffs = staffs;
}
@Override
public int getRowCount() {
return staffs.size();
}
@Override
public int getColumnCount() {
return 5;
}
@Override
public String getColumnName(int columnIndex) {
switch (columnIndex){
case 0:
return "First Name";
case 1:
return "Second Name";
case 2:
return "Date";
case 3:
return "Position";
case 4:
return "Salary";
}
return "";
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 嗨,
我是Java新手并试图找出如何将这些数据推入数组(6行,3列)?
x1 John 6
x2 Smith 9
x3 Alex 7
y1 Peter 8
y2 Frank 9
y3 Andy 4
Run Code Online (Sandbox Code Playgroud)
之后,我将从最后一栏获取数字进行数学计算.
这是我的代码......
public class Testing {
public static void main(String[] args) {
Employee eh = new Employee_hour();
Employee_hour [] eh_list = new Employee_hour[6];
eh_list[0] = new Employee_hour("x1", "John", 6);
eh_list[1] = new Employee_hour("x2", "Smith", 9);
eh_list[2] = new Employee_hour("x3", "Alex", 7);
eh_list[3] = new Employee_hour("y1", "Peter", 8);
eh_list[4] = new Employee_hour("y2", "Frank", 9);
eh_list[5] = new Employee_hour("y3", "Andy", 4);
print(eh_list); …Run Code Online (Sandbox Code Playgroud)