小编jht*_*jht的帖子

IntentService错误:无默认构造函数

我是Android的新手,我正在尝试使用IntentService,错误是它没有默认构造函数我尝试重启android工作室它不起作用.

package com.example.hitesh.kuchbhi;

import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.app.NotificationCompat;

import java.util.TreeSet;

public class DisplayNotification extends IntentService {
    public DisplayNotification(String name) {
        super("DisplayNotification");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
// my code which even after deleting gives the same error
    }
Run Code Online (Sandbox Code Playgroud)

log cat错误

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.hitesh.kuchbhi, PID: 28899
                  java.lang.RuntimeException: Unable to instantiate service com.example.hitesh.kuchbhi.DisplayNotification: java.lang.InstantiationException: class com.example.hitesh.kuchbhi.DisplayNotification has no zero argument constructor
                      at android.app.ActivityThread.handleCreateService(ActivityThread.java:2728)
                      at android.app.ActivityThread.access$1800(ActivityThread.java:144)
                      at …
Run Code Online (Sandbox Code Playgroud)

android

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

如何对接口的null引用返回值?

代码是:

interface I {
    int i = 0;
    void display();
}

class A implements I {
    I i1;

    public static void main(String[] args) {
        A a = new A();
        a.display();
    }

    public void display() {
        System.out.println(i1); //1
        System.out.println(i1.i); //2
    }
}
Run Code Online (Sandbox Code Playgroud)

代码的输出是

null
0
Run Code Online (Sandbox Code Playgroud)

但是当地址i是null,那么在第二个i1.i如何返回一个值?如何使用null引用指向变量?

java

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

为什么5.0 == 5L给我一个真实的回报?

System.out.println(" answer is " + (5.0==5L));
Run Code Online (Sandbox Code Playgroud)

这回来了true!它应该返回一个false值,因为正在比较两种不同的类型.即使将double其与long价值进行比较!

java equality

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

为什么这个同步方法会给我一个错误?

//What will happen when you attempt to compile and run the following code?

public class TestThread extends Thread {
    public static void main(String[] args) {
        new TestThread().start();
        new TestThread().start();
    }

    public void run() {
        Safe s1 = new Safe("abc");
        Safe s2 = new Safe("xyz");
    }
}

class Safe {
    String  str;

    public synchronized Safe(String s) {
        str = s;
        str = str.toUpperCase();
        System.out.print(str + " ");
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么这个方法公共同步安全(String S)给我一个编译错误?我知道我们无法同步变量,但上面的代码出了什么问题?!?!

java

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

标签 统计

java ×3

android ×1

equality ×1