我是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) 代码是:
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引用指向变量?
System.out.println(" answer is " + (5.0==5L));
Run Code Online (Sandbox Code Playgroud)
这回来了true!它应该返回一个false值,因为正在比较两种不同的类型.即使将double其与long价值进行比较!
//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)给我一个编译错误?我知道我们无法同步变量,但上面的代码出了什么问题?!?!