想知道REST和JSON API之间的区别是什么,如何与它们进行交互,以及如何解析结果.我的目标是为我的Android手机建立一个小应用程序,告诉我下一班火车何时通过我的房子到达地铁站,使用运输代理商提供的开发人员API.
我正在大学学习C++,但希望用Java来解决这个问题.如果这更像是一个讨论问题而不是黑白问题,我很抱歉,但我在其他地方找不到任何信息.
我正在为人工智能学期项目编写Android游戏应用程序.我在主类的第38行得到一个NullPointerException,它是启动屏幕上新游戏按钮的setOnClickListener.
相关章节类WW3活动:
public class WW3Activity extends Activity
{
public boolean DebugMode = false;
private String buildMenuEmplacement = "";
//[Initialization] Called when the app is first launched
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.startscreen);
//[Initialization] Makes the button resources available to the class
final Button newGame = (Button) findViewById(R.id.buttonNewGame);
final Button loadGame = (Button) findViewById(R.id.buttonLoadGame);
final Button exitGame = (Button) findViewById(R.id.buttonExit);
final Button about = (Button) findViewById(R.id.buttonAbout);
final Button troll = (Button) findViewById(R.id.buttonTroll);
final Button debug = (Button) findViewById(R.id.buttonDebug);
//[Action] …Run Code Online (Sandbox Code Playgroud) 我试图使用pthreads和信号量解决生产者 - 消费者问题,但看起来生产者线程没有生成,消费者线程也不消耗.似乎正在创建线程:
/* Do actual work from this point forward */
/* Create the producer threads */
for(c1=1; c1<=argarray[1]; c1++)
{
pthread_create(&tid, &attr, producer, NULL);
printf("Creating producer #%d\n", c1);
}
/* Create the consumer threads */
for(c1=1; c1<=argarray[2]; c1++)
{
pthread_create(&tid, &attr, consumer, NULL);
printf("Creating consumer #%d\n", c1);
}
Run Code Online (Sandbox Code Playgroud)
因为"创建生产者#x"和"创建消费者#x"被打印到屏幕上.但是,它不会从线程内部打印出来:
if(insert_item(item))
{
fprintf(stderr, "Producer error.");
}
else
{
printf("Producer produced %d\n", item);
}
Run Code Online (Sandbox Code Playgroud)
同样用于消费者线程.完整代码:
#include "buffer.h"
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <semaphore.h>
/* Create Buffer */
buffer_item …Run Code Online (Sandbox Code Playgroud) 我已经使用Google的教程实现了登录,但该按钮并不适合我正在使用它的网站的设计.我想使用我的图形设计师制作的图像.目前是否可以使用自定义图像登录按钮?
有点奇怪的问题.我打开了我的eclipse工作区,并试图启动我的Android应用程序来测试它,并抛出一个NullPointerException启动应用程序.甚至还没到应用程序.
eclipse.buildId=M20100211-1343
java.version=1.7.0
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86
Error
Sat Nov 12 11:23:25 EST 2011
An internal error occurred during: "Launching ww3".
java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launch(AndroidLaunchController.java:357)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.doLaunch(LaunchConfigDelegate.java:321)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:237)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:866)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1069)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Run Code Online (Sandbox Code Playgroud)
编辑:仍然没有.更改JDK版本的结果:
eclipse.buildId=M20100211-1343
java.version=1.6.0_18
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个树,每个节点有六个孩子.我为生成树而编写的方法genB导致堆栈溢出.
public class TreeTest
{
public static void main(String Args[])
{
sBNode bTree;
sWNode wTree;
bTree = new sBNode();
wTree = new sWNode();
TreeTest ai = new TreeTest();
bTree.depth = 0;
System.out.println(bTree.depth);
ai.genB(bTree, 2);
ai.printTree(bTree);
}
public Treetest()
{
}
public boolean leaf(sBNode node)
{
if(node.pe1==null && node.pe2==null && node.pe3==null && node.ee1==null && node.ee2==null && node.ee3==null)
return true;
else
return false;
}
public void genB(sBNode parent, int ddepth)
{
int pdepth;
if(parent.depth != ddepth)
{
System.out.println(parent.depth);
pdepth = parent.depth++;
sBNode …Run Code Online (Sandbox Code Playgroud) 我有一个函数应该计算一个字母在一个句子中出现的次数,并根据它,计算它在句子中发生的概率.要做到这一点,我有一句话:
华盛顿都市区是美国受教育程度最高,最富裕的大都市区.
一组结构,包含字母,它出现的次数,以及它发生的概率,每个字母字符有一个结构,标点符号和空格有一个附加结构:
struct letters
{
char letter;
int occur;
double prob;
}box[53];
Run Code Online (Sandbox Code Playgroud)
这是函数本身:
void probability(letters box[53], int sum
{
cout<<sum<<endl<<endl;
for(int c8=0;c8<26;c8++)
{
box[c8].prob = (box[c8].occur/sum);
cout<<box[c8].letter<<endl;
cout<<box[c8].occur<<endl;
cout<<box[c8].prob<<endl<<endl;
}
}
Run Code Online (Sandbox Code Playgroud)
它正确地识别出第一行中句子中有90个字母,根据for循环第二行中的结构打印出大写字母,并打印出它出现的次数.它连续打印0表示概率.我究竟做错了什么?