小编Joa*_*uer的帖子

为什么即使没有任何错误,编译器也不会运行程序?

我有一个程序在Eclipse中没有显示任何错误,但每当我点击运行按钮时,没有任何反应.我在下面附带的编译器控制台中获得了代码行.

import java.awt.*;
import javax.swing.*;

import java.awt.event.*;

public class Transaction extends JFrame {

private static final long serialVersionUID = 1L;
JFrame frame = new JFrame("Bank Account - S Standridge");
JMenuBar MenuBar;
JMenu File = new JMenu("File");
JMenu Edit = new JMenu("Edit");
JMenu About = new JMenu("About");
JMenuItem Transaction = new JMenuItem("Transaction");
JMenuItem Summary = new JMenuItem("Summary");
JMenuItem Exit = new JMenuItem("Exit");
private JPanel MenuPanel;
private JPanel TransactionPanel;
private JPanel ButtonPanel;
private JButton calcButton;    
private JButton exitButton; 
private JMenuItem SummaryMenuItem;
private …
Run Code Online (Sandbox Code Playgroud)

java swing jmenubar jmenu

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

C:指针混乱

我明白这是基本的东西的一部分,但我被卡住了:-(有人可以帮帮我吗?

计划1:

#include <stdio.h>
#include <stdlib.h> 

int main()
{
 int a=1,b=2,c;
 c=(a+b)++;
}
Run Code Online (Sandbox Code Playgroud)

为什么输出错误?是否需要左值?

计划2:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
 char *p1="name";
 char *p2;

 p2=(char*)malloc(20);
 memset(p2,0,20);

 while(*p2++=*p1++);
 printf("%s\n",p2);

}
Run Code Online (Sandbox Code Playgroud)

为什么是输出,一个空字符串?如果我颠倒增量的顺序,那就是:while(++*p2=++*p1);为什么左值误差来了?

c pointers lvalue post-increment

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

Java Arraylist使用元素

我有一个ArrayListString[].

每个String[]包含两个值:值和日期.

如果我打印它,它看起来像这样:

 value | date
-------|----------
 357.0 | 2011/05/30
-234.0 | 2011/05/31
-123.0 | 2011/05/30

我想创建一个新的ArrayList,在同一日期的所有值相加.像这样:

 value | date
-------|----------
 234.0 | 2011/05/30
-234.0 | 2011/05/31

有人可以帮忙吗?

java arrays arraylist

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

尝试编译程序时出错

我正在尝试运行从Sun Java站点获取的代码(我没有复制它,查看它并编写它,因为它可以帮助我记住代码).

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CharEx{
    FileReader inputStream = null;
        FileWriter outputStream = null;

    public static void main(String args[]) throws IOException{
        FileReader inputStream = null;
        FileWriter outputStream = null;

        try{
            inputStream = FileReader("xanadu.txt");
            outputStream = FileWriter("out.txt");
            int c;
            while ((c = inputStream.read()) != -1){
                outputStream(c);
            } 
        }
        finally{
            if(inputStream !=null){
                inputStream.close();
            }
            if(outputStream !=null){
                outputStream.close();
            }

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我遇到了错误.

D:\Java>javac CharEx.java
CharEx.java:14: cannot find symbol
symbol  : method FileReader(java.lang.String)
location: class CharEx
                        inputStream = …
Run Code Online (Sandbox Code Playgroud)

java io filereader filewriter

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

如何在Android中创建一个无法被Advanced Task Killer杀死的服务

我创建了一个安全应用程序,就像Mcafee wave secure一样.
我的应用程序正在侦听SMS命令并在命令匹配时执行某些操作,因此我创建了一个表单,其中包含另一个用于侦听SMS的服务.

这是主要形式:

public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
ArrayList<String> messageList;
ArrayAdapter< String> adapter;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //untuk mendisable notification area
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);
    MainButtonAbout=(Button) findViewById(R.id.MainbuttonAbout);
    MainButtonHelp=(Button) findViewById(R.id.MainbuttonHelp);
    MainButtonWizard=(Button) findViewById(R.id.MainbuttonWizard);
    MainButtonOption=(Button) findViewById(R.id.MainbuttonOption);
    MainCheckBoxActive=(CheckBox)findViewById(R.id.MaincheckBoxActive);

    MainButtonAbout.setOnClickListener(this);
    MainButtonHelp.setOnClickListener(this);
    MainButtonWizard.setOnClickListener(this);
    MainButtonOption.setOnClickListener(this);

    startService(new Intent(MainForm.this, ListenSMSservice.class));

    MainCheckBoxActive.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (buttonView.isChecked())
            {
                Toast.makeText(MainForm.this, "Your Device is Protected Now!!", 1).show();              
                startService(new Intent(MainForm.this, ListenSMSservice.class));
            }
            else
            {
                Toast.makeText(MainForm.this, …
Run Code Online (Sandbox Code Playgroud)

java android android-widget android-ndk android-manifest

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

如何将两个JSON格式的Java字符串一起添加?

我有两个JSON格式字符串

 {"user1":{"Iden":4,"nID":1},"user2":{"Iden":5,"nID":1}} // String A JSON 

 {"user1":{"Iden":4,"nID":1},"user3":{"Iden":6,"nID":1},"user2":{"Iden":5,"nID":1}}  
Run Code Online (Sandbox Code Playgroud)

在下面的程序中,上面的JSON由Eclipse IDE格式化

这是我的计划:

import java.util.Map;

import org.codehaus.jackson.type.TypeReference;

import com.tradeking.at.util.JsonHelper;

public class Hi {
    private static JsonHelper jsonHelper = JsonHelper.getInstance();

    public static void main(String[] args) throws Exception {

        Map<String, Tracker> totalCusts = null;

        String A = "{\"user1\":{\"Iden\":4,\"nID\":1},\"user2\":{\"Iden\":5,\"nID\":1}}";
        String B = "{\"user1\":{\"Iden\":4,\"nID\":1},\"user3\":{\"Iden\":6,\"nID\":1},\"user2\":{\"Iden\":5,\"nID\":1}}";

        String totalString =  A+B;

        if (null != totalString) {
            totalCusts = (Map<String, Tracker>) jsonHelper.toObject(
                    totalString, new TypeReference<Map<String, Tracker>>() {
                    });

        }

        System.out.println(totalCusts);

    }

}
Run Code Online (Sandbox Code Playgroud)

Tracker.java:

import org.json.JSONObject;

public class Tracker extends JSONObject{

} …
Run Code Online (Sandbox Code Playgroud)

java json

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

Google的libphonenumber有多准确?

我想将Google的libphonenumber库合并到我正在研究的CRM解决方案中,以识别以下内容:

  • 电话号码是移动电话还是固定电话
  • 地理位置的数字

我已经在线进行了一些搜索,似乎无法找到任何讨论库用于确定此信息的算法,以及这些方法的可靠性.

是否有任何此类文档(即这些算法的详细信息及其各自的可靠性)?或者真的,有什么可以帮助我理解这个库的封面发生了什么?

libphonenumber

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

HashSet不会拒绝第二次添加调用

我刚刚开始使用Collection,我已经编写了代码来测试 HashSet

这是代码(Person.java):

public class Person
{
  int id;

  public Person(int id)
  {
    this.id=id;
  }

  public int getId()
  {
    return id;
  }

  public void setId(int id)
  {
    this.id=id;
  }

  public boolean equals(Object o)
  {
    if (o instanceof Person)
    {
      Person p=(Person)o;
      if (this.id==p.id)
        return false;
      else
        return true;
    }
    else return false;
  }

  public int hashCode()
  {
    return 21*id;
  }
}
Run Code Online (Sandbox Code Playgroud)

和Implementation类,只是一个简单的类:

import java.util.*;

class HashSetTest
{
  public static void main(String[] args)
  {
    Set<Person> set=new HashSet<Person>();
    Person p1=new Person(6);
    Person …
Run Code Online (Sandbox Code Playgroud)

java collections hashset

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

将List转换为MultiKeyMap时,为什么不会出现编译错误?

我刚刚遇到一段代码,它将一个aList转换成一个MultiKeyMap调用一个带有MultiKeyMapas参数的方法的代码:

someMethod ((MultiKeyMap) myList);
Run Code Online (Sandbox Code Playgroud)

哪里myListList.

当然,它会ClassCastException在运行时抛出.为什么它没有显示编译错误或至少有一个警告"类型安全:未经检查的强制转换",因为在尝试将其Collection转换为Map?两种类型都没有任何共同之处.

java casting

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

将元素添加到wildchar列表会导致编译错误

我有一个列表包含未来的任务,未来的类型是未知的,所以我创建一个带通配符类型的列表?,但是当我向列表中添加一个元素时,就会发生编译错误.

这是代码:

private List<Pair<String, Future<?>>> futureTasks = Collections.synchronizedList(
        new ArrayList<Pair<String, Future<?>>>(8));

// taskId is a string
futureTasks.add(Pair.makePair(taskId, getExecutors().submit(
    new Callable<String>() {
        public String call() {
            try {
                return exportAccountSrcTask(tmpFile); // return a string
            } catch (Exception e) {
                logger.error("failed to export account src", e);
            }
            return null;
    }}))
);
Run Code Online (Sandbox Code Playgroud)

编译错误:

add(Pair<String,Future<?>>)类型中的方法List<Pair<String,Future<?>>>不适用于参数(Pair<String,Future<String>>)

java generics

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