我正在用Java编写一个程序,它显示了一系列的课后俱乐部(EG Football,Hockey - 由用户输入).俱乐部添加到以下内容ArrayList
:
private ArrayList<Club> clubs = new ArrayList<Club>();
Run Code Online (Sandbox Code Playgroud)
通过以下方法:
public void addClub(String clubName) {
Club club = findClub(clubName);
if (club == null)
clubs.add(new Club(clubName));
}
Run Code Online (Sandbox Code Playgroud)
'Club'是一个带有构造函数的类 - 名称:
public class Club {
private String name;
public Club(String name) {
this.name = name;
}
//There are more methods in my program but don't affect my query..
}
Run Code Online (Sandbox Code Playgroud)
我的程序正在运行 - 它允许我在我的arraylist中添加一个新的Club对象,我可以查看arraylist,我可以删除任何我想要的等等.
但是,我现在想将该arrayList(俱乐部)保存到文件中,然后我希望能够稍后加载该文件并再次使用相同的arraylist.
我有两种方法(见下文),并一直试图让它工作,但没有任何帮助,任何帮助或建议将不胜感激.
保存方法(fileName由用户选择)
public void save(String fileName) throws FileNotFoundException {
String tmp = clubs.toString();
PrintWriter pw = …
Run Code Online (Sandbox Code Playgroud) 我的问题是我正在将地图内容序列化为JSON.
在输出(JSON)中,我有跟随键/名称语法规则的对象.
密钥是从map键创建的,名称来自值.
模型示例:
class Storage {
Map<String,String> values = new HashMap<>();
{
map.put("key1","key1");
map.put("key2","key2");
map.put("key3","key3");
}
}
Run Code Online (Sandbox Code Playgroud)
JSON示例对象:
{
key1=value1,
key2=value2,
key3=value3
}
Run Code Online (Sandbox Code Playgroud)
JSON架构:
{
"name": "storage",
"description": "Store of key values",
"properties": {
// How can we describe the properties if we do not know the name ?
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,我不知道它的价值是什么,但我知道它们会是一些.
你能帮我提一下架构的完整定义吗?
免责声明:
我知道这也可以序列化为
{
values: [
{key="key1", value="value1"},
{key="key2", value="value2"},
{key="key3", value="value3"}
]
}
Run Code Online (Sandbox Code Playgroud)
但是不希望在JSON中有数组.
我是angular2的新手.我试图了解如何<router-outlets>
在特定模板中使用多个.我在这里经历了很多质量保证,但无法解决我的错误.
router.module.ts
const routes: Routes = [
{
path: '',
redirectTo: 'one',
pathMatch: 'full'
},
{
path: 'two',
component: ClassTwo, children: [
{
path: 'three',
component: ClassThree,
outlet: 'nameThree',
},
{
path: 'four',
component: ClassFour,
outlet: 'nameFour'
}
]
},];
Run Code Online (Sandbox Code Playgroud)
component1.html
<h3>In One</h3>
<nav>
<a routerLink="/two" class="dash-item">...Go to Two...</a>
<a routerLink="/three" class="dash-item">... Go to THREE...</a>
<a routerLink="/four" class="dash-item">...Go to FOUR...</a>
</nav>
<router-outlet></router-outlet> // Successfully loaded component2.html
<router-outlet name="nameThree" ></router-outlet> // Error: Cannot match any routes. URL Segment: 'three' …
Run Code Online (Sandbox Code Playgroud) 我需要for
在JSTL/EL中表示以下循环(在Java上下文中).
for (int i = 6; i <= 15; i++) {
System.out.print(i+"\t");
}
Run Code Online (Sandbox Code Playgroud)
它将显示以下输出.
6 7 8 9 10 11 12 13 14 15
Run Code Online (Sandbox Code Playgroud)
我怎样才能在JSTL/EL中做同样的事情?我对它没有确切的想法.我只想尝试以下方法.
<c:forEach begin="6" end="15" varStatus="loop">
<c:out value="${loop.count}"/>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
它显然会显示以下输出.
1 2 3 4 5 6 7 8 9 10
Run Code Online (Sandbox Code Playgroud)
这不是我想要的.我需要在6
和15
之间显示数字(即在指定范围之间).我需要在Web应用程序中使用这样的概念来实现分页.我可以用EL吗?
\t
在这个声明System.out.print(i+"\t");
中并不重要.
只要我知道,"启用AP"的方法没有API,但我可以使用反射来设置它.这就是我的所作所为
wifi_manager = (WifiManager) this.getSystemService(HotSpot_TrisActivity.this.WIFI_SERVICE);
btnEnableAP = (Button)findViewById(R.id.btnEnableAP);
btnEnableAP.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
WifiConfiguration wifi_configuration = null;
wifi_manager.setWifiEnabled(false);
try
{
//USE REFLECTION TO GET METHOD "SetWifiAPEnabled"
Method method=wifi_manager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifi_manager, wifi_configuration, true);
}
catch (NoSuchMethodException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (InvocationTargetException e)
{ …
Run Code Online (Sandbox Code Playgroud) 我刚刚发现basic_string的两个交换函数(命名空间std中的成员函数和函数)没有用noexcept声明- 既不是在GCC-4.8的标准库中也不是在最新的C++草案N3690中.
另一方面,移动构造函数以及移动赋值运算符使用noexcept声明.这表明应该可以提供noexcept交换功能.
问题:没有使用noexcept声明交换函数的原因是什么?
更新:问题是我想在我自己的交换函数中使用模板函数,它使用static_assert检查交换是否实际上是noexcept,例如:
struct foo {
bar_t bar;
baz_t baz;
void swap(foo& rhs) noexcept {
swap_noexcept(bar, rhs.bar);
swap_noexcept(baz, rhs.baz);
}
};
Run Code Online (Sandbox Code Playgroud)
但是,只有在使用noexcept声明交换函数时才有效,但情况并非如此basic_string
.
我尝试以最简单的方式使用扫描仪:
码:
double gas, efficiency, distance, cost;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of gallons of gas in the tank: ");
gas = scanner.nextDouble();
System.out.print("Enter the fuel efficiency: ");
efficiency = scanner.nextDouble();
Run Code Online (Sandbox Code Playgroud)
但在第一次输入后5.1
它抛出:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextDouble(Scanner.java:2456)
at udacity.MileagePrinter.main(MileagePrinter.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Run Code Online (Sandbox Code Playgroud)
该JavaDoc中的状态:
由扫描程序抛出,表示检索到的令牌
与预期类型的模式不匹配,或者令牌超出预期类型的范围.
但在我看来,所有看起来都正确,并且应该工作正常.
问题:
我编写了这个简单的Test
类来了解Java如何boolean
在字节码级别评估代数:
public class Test {
private static boolean a, b;
public static boolean method1(){
return !(a || b);
}
public static boolean method2(){
return !a && !b;
}
}
Run Code Online (Sandbox Code Playgroud)
如果你简化method1()
使用DeMorgan的法则,你应该得到method2()
.在查看字节码(使用javap -c Test.class)后,它看起来像:
Compiled from "Test.java"
public class Test {
public Test();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":
()V
4: return
public static boolean method1();
Code:
0: getstatic #2 // Field a:Z
3: ifne 16
6: getstatic #3 …
Run Code Online (Sandbox Code Playgroud) 我的问题是如下.
android:Theme.NoTitleBar.Fullscreen
,只有一个Activity
,所有其他视图都是Fragment
WebView
里面ViewPager Fragment
有里面的东西ScrollView
WebView
Window
调整大小/平移我已经尝试过设置android:windowSoftInputMode="adjustResize"
或者android:windowSoftInputMode="adjustPan"
在我的清单中Activity
.还尝试在java中设置其中一个.
我的应用程序中的正常EditText
内部ScrollView
确实正确调整平移,以便用户可以看到他/她正在键入的位置.
更新:
如果没有工作解决方案来调整窗口,有没有办法WebView
认为它的内容就像半屏高度更大,所以用户至少可以滚动输入可见.
我正在努力,Backbone.js
我想知道你是否可以像设置模型的默认值一样设置默认值?
java ×5
android ×2
javascript ×2
angular ×1
arraylist ×1
backbone.js ×1
bytecode ×1
c++ ×1
c++11 ×1
el ×1
for-loop ×1
inputstream ×1
json ×1
jsonschema ×1
jsp ×1
jstl ×1
outputstream ×1
text-files ×1