我试图在我的设备上测试我的应用程序,但我一直收到错误告诉我
不幸的是我的应用必须关闭
我进行了搜索,发现this answer here on Stackoverflow我已按照相关步骤编辑了我的源查找路径,现在它类似于以下内容:
但是,我的程序仍然告诉我它需要关闭。还有什么我需要做的吗?
09-05 15:31:56.695: D/OpenGLRenderer(3941): Enabling debug mode 0
09-05 15:39:30.157: E/InputEventReceiver(3941): Exception dispatching input event.
09-05 15:39:30.157: E/MessageQueue-JNI(3941): Exception in MessageQueue callback: handleReceiveCallback
09-05 15:39:30.217: E/MessageQueue-JNI(3941): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.bletest/com.example.bletest.DeviceScanActivity}; have you declared this activity in your AndroidManifest.xml?
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Activity.startActivityForResult(Activity.java:3390)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Activity.startActivityForResult(Activity.java:3351)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Activity.startActivity(Activity.java:3587)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Activity.startActivity(Activity.java:3555)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at com.example.bletest.MainActivity$1.onTouch(MainActivity.java:43)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.View.dispatchTouchEvent(View.java:7379)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.View.dispatchPointerEvent(View.java:7564)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.os.MessageQueue.nativePollOnce(Native Method)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.os.MessageQueue.next(MessageQueue.java:132)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.os.Looper.loop(Looper.java:124)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at java.lang.reflect.Method.invokeNative(Native Method)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at java.lang.reflect.Method.invoke(Method.java:525)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-05 15:39:30.217: E/MessageQueue-JNI(3941): at dalvik.system.NativeStart.main(Native Method)
09-05 15:42:49.682: D/AndroidRuntime(3941): Shutting down VM
09-05 15:42:49.682: W/dalvikvm(3941): threadid=1: thread exiting with uncaught exception (group=0x41573700)
09-05 15:42:49.752: E/AndroidRuntime(3941): FATAL EXCEPTION: main
09-05 15:42:49.752: E/AndroidRuntime(3941): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.bletest/com.example.bletest.DeviceScanActivity}; have you declared this activity in your AndroidManifest.xml?
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Activity.startActivityForResult(Activity.java:3390)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Activity.startActivityForResult(Activity.java:3351)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Activity.startActivity(Activity.java:3587)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Activity.startActivity(Activity.java:3555)
09-05 15:42:49.752: E/AndroidRuntime(3941): at com.example.bletest.MainActivity$1.onTouch(MainActivity.java:43)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.View.dispatchTouchEvent(View.java:7379)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1954)
09-05 15:42:49.752: E/AndroidRuntime(3941): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
09-05 15:42:49.752: E/AndroidRuntime(3941): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
09-05 15:42:49.752: E/AndroidRuntime(3941): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.View.dispatchPointerEvent(View.java:7564)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.os.MessageQueue.nativePollOnce(Native Method)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.os.MessageQueue.next(MessageQueue.java:132)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.os.Looper.loop(Looper.java:124)
09-05 15:42:49.752: E/AndroidRuntime(3941): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-05 15:42:49.752: E/AndroidRuntime(3941): at java.lang.reflect.Method.invokeNative(Native Method)
09-05 15:42:49.752: E/AndroidRuntime(3941): at java.lang.reflect.Method.invoke(Method.java:525)
09-05 15:42:49.752: E/AndroidRuntime(3941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-05 15:42:49.752: E/AndroidRuntime(3941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-05 15:42:49.752: E/AndroidRuntime(3941): at dalvik.system.NativeStart.main(Native Method)
09-05 15:43:21.983: I/System.out(4215): Sending WAIT chunk
09-05 15:43:21.983: W/ActivityThread(4215): Application com.example.bletest is waiting for the debugger on port 8100...
09-05 15:43:21.993: I/dalvikvm(4215): Debugger is active
09-05 15:43:22.183: I/System.out(4215): Debugger has connected
09-05 15:43:22.183: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:22.384: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:22.584: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:22.784: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:22.994: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:23.194: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:23.395: I/System.out(4215): waiting for debugger to settle...
09-05 15:43:23.595: I/System.out(4215): debugger has settled (1477)
09-05 15:43:24.946: D/dalvikvm(4215): threadid=1: still suspended after undo (sc=1 dc=1)
09-05 15:44:00.411: D/libEGL(4215): loaded /system/lib/egl/libEGL_adreno200.so
09-05 15:44:00.411: D/libEGL(4215): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
09-05 15:44:00.421: D/libEGL(4215): loaded /system/lib/egl/libGLESv2_adreno200.so
09-05 15:44:00.431: I/Adreno200-EGL(4215): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM Build: Iabe52cfaeae4c5fab1acacfe6f056ba15fa93274
09-05 15:44:00.461: D/OpenGLRenderer(4215): Enabling debug mode 0
`
清单xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.example.example.DeviceScanActivity" />
<activity
android:name="com.example.bletest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
package com.example.bletest;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.Button;
公共类MainActivity扩展Activity { 按钮aButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListeners();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void addListeners() {
Button btnCallMethod = (Button) this.findViewById(R.id.btnCallMethod);
// CALL METHOD BUTTON
btnCallMethod.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Intent intent = new Intent(getApplicationContext(), DeviceScanActivity.class);
startActivity(intent); // start the DeciveScanActivity
}
return false;
}
});
}
}
DeviceScanAcitivity.java我试图暗示的类和代码:
package com.example.bletest;
import android.annotation.TargetApi; import android.app.ListActivity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.widget.ArrayAdapter;
@TargetApi(18) 公共类DeviceScanActivity扩展了ListActivity {
private Handler mHandler;
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 10000;
private ArrayAdapter<Object> list;
protected void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
int key = b.getInt("yourKey");
switch(key)
{
case 1: // call method here
list = new ArrayAdapter<Object>(getApplicationContext(),
android.R.layout.simple_list_item_1);
setListAdapter(list);
scanLeDevice(true);
}
}
@TargetApi(18)
public void scanLeDevice(final boolean enable) {
list.add("Scanning...");
final BluetoothAdapter adapter = getBluetoothAdapter();
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
// mBluetoothAdapter.stopLeScan(mLeScanCallback);
adapter.stopLeScan(callback);
list.clear();
}
}, SCAN_PERIOD);
adapter.startLeScan(callback);
} else {
adapter.stopLeScan(callback);
}
}
@TargetApi(18)
private BluetoothAdapter getBluetoothAdapter()
{
BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
return manager.getAdapter();
}
private final BluetoothAdapter.LeScanCallback callback = new BluetoothAdapter.LeScanCallback()
{
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
// TODO Auto-generated method stub
{
list.add("found: " + device);
runOnUiThread(new Runnable(){
@Override
public void run()
{
list.add(device);
list.notifyDataSetChanged();
}
});
}
}
};
}
答案 0 :(得分:0)
更改清单
下面的行<activity android:name="com.example.example.DeviceScanActivity" />
用这个
<activity android:name="com.example.bletest.DeviceScanActivity" />
它会起到魅力的作用:)
P.S: - 错误在您的活动路径/位置名称中。