我到了那里!
logcat的:
07-29 19:15:05.509: D/libEGL(31021): loaded /system/lib/egl/libEGL_mali.so
07-29 19:15:05.544: D/libEGL(31021): loaded /system/lib/egl/libGLESv1_CM_mali.so
07-29 19:15:05.549: D/libEGL(31021): loaded /system/lib/egl/libGLESv2_mali.so
07-29 19:15:05.549: D/(31021): Device driver API match
07-29 19:15:05.549: D/(31021): Device driver API version: 10
07-29 19:15:05.549: D/(31021): User space API version: 10
07-29 19:15:05.549: D/(31021): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Mon Mar 5 09:47:55 KST 2012
07-29 19:15:05.574: D/OpenGLRenderer(31021): Enabling debug mode 0
07-29 19:15:07.509: W/IInputConnectionWrapper(31021): showStatusIcon on inactive InputConnection
07-29 19:15:08.444: D/dalvikvm(31021): newInstance failed: no <init>()
07-29 19:15:08.444: D/AndroidRuntime(31021): Shutting down VM
07-29 19:15:08.444: W/dalvikvm(31021): threadid=1: thread exiting with uncaught exception (group=0x41443300)
07-29 19:15:08.549: E/AndroidRuntime(31021): FATAL EXCEPTION: main
07-29 19:15:08.549: E/AndroidRuntime(31021): java.lang.RuntimeException: Unable to instantiate receiver com.liamwli.parent.trap.ParentTrap$Controller: java.lang.InstantiationException: can't instantiate class com.liamwli.parent.trap.ParentTrap$Controller; no empty constructor
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2333)
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.app.ActivityThread.access$1500(ActivityThread.java:139)
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.os.Looper.loop(Looper.java:137)
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.app.ActivityThread.main(ActivityThread.java:4896)
07-29 19:15:08.549: E/AndroidRuntime(31021): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 19:15:08.549: E/AndroidRuntime(31021): at java.lang.reflect.Method.invoke(Method.java:511)
07-29 19:15:08.549: E/AndroidRuntime(31021): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
07-29 19:15:08.549: E/AndroidRuntime(31021): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
07-29 19:15:08.549: E/AndroidRuntime(31021): at dalvik.system.NativeStart.main(Native Method)
07-29 19:15:08.549: E/AndroidRuntime(31021): Caused by: java.lang.InstantiationException: can't instantiate class com.liamwli.parent.trap.ParentTrap$Controller; no empty constructor
07-29 19:15:08.549: E/AndroidRuntime(31021): at java.lang.Class.newInstanceImpl(Native Method)
07-29 19:15:08.549: E/AndroidRuntime(31021): at java.lang.Class.newInstance(Class.java:1319)
07-29 19:15:08.549: E/AndroidRuntime(31021): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2328)
07-29 19:15:08.549: E/AndroidRuntime(31021): ... 10 more
07-29 19:15:09.719: I/Process(31021): Sending signal. PID: 31021 SIG: 9
的活动:
package com.liamwli.parent.trap;
import android.os.Bundle;
import android.app.Activity;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
public class ParentTrap extends Activity {
Button dae, dad, spass;
EditText pass;
ComponentName mDeviceAdminSample;
static final int RESULT_ENABLE = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dae = (Button) findViewById(R.id.benablea);
dae.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mDeviceAdminSample = new ComponentName(ParentTrap.this,
Controller.class);
Intent intent = new Intent(
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"Title");
startActivityForResult(intent, RESULT_ENABLE);
}
});
dad = (Button) findViewById(R.id.button1);
dad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
spass = (Button) findViewById(R.id.button2);
spass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
pass = (EditText) findViewById(R.id.editText1);
dad.setEnabled(false);
}
public class Controller extends DeviceAdminReceiver {
void showToast(Context context, String msg) {
String status = "Status";
Toast.makeText(context, status, Toast.LENGTH_SHORT).show();
}
@Override
public void onEnabled(Context context, Intent intent) {
showToast(context, "Enabled");
}
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
return "Disable Requested";
}
@Override
public void onDisabled(Context context, Intent intent) {
showToast(context, "Disabled");
}
@Override
public void onPasswordChanged(Context context, Intent intent) {
showToast(context, "Device PIN Changed");
}
}
}
class evilliam {
}
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.main, menu);
// return true;
// }
请帮我解决这个问题,我保证在明天之前不要打扰你。)
答案 0 :(得分:1)
Caused by: java.lang.InstantiationException: can't instantiate class com.liamwli.parent.trap.ParentTrap$Controller; no empty constructor
这表明Controller需要一个默认构造函数,如下所示:
public class Controller extends DeviceAdminReceiver {
public Controller() {
super();
}
void showToast(Context context, String msg) {
String status = "Status";
Toast.makeText(context, status, Toast.LENGTH_SHORT).show();
//Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
...
}