我的应用程序一直在崩溃

时间:2013-04-05 23:35:36

标签: android eclipse adt

我在eclipse中创建了一个应用程序,并且每当我想打开它时它都会继续崩溃。应用程序应该能够在收到特定措辞的文本消息时关闭手机。它确实需要root权限。另外我运行它的方式是按下eclipse上的运行按钮,它表明我没有编码错误,所以你可以看到我很丢失。

这是日志文件:

04-05 23:19:31.638: E/Trace(962): error opening trace file: No such file or directory (2)
04-05 23:19:32.294: D/AndroidRuntime(962): Shutting down VM
04-05 23:19:32.354: W/dalvikvm(962): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-05 23:19:32.459: E/AndroidRuntime(962): FATAL EXCEPTION: main
04-05 23:19:32.459: E/AndroidRuntime(962): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.rabazid.abzsmspoweroff/com.rabazid.abzsmspoweroff.SmsLoggerActivity}: java.lang.ClassNotFoundException: Didn't find class "com.rabazid.abzsmspoweroff.SmsLoggerActivity" on path: /data/app/com.rabazid.abzsmspoweroff-1.apk
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.os.Looper.loop(Looper.java:137)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.ActivityThread.main(ActivityThread.java:5041)
04-05 23:19:32.459: E/AndroidRuntime(962):  at java.lang.reflect.Method.invokeNative(Native Method)
04-05 23:19:32.459: E/AndroidRuntime(962):  at java.lang.reflect.Method.invoke(Method.java:511)
04-05 23:19:32.459: E/AndroidRuntime(962):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-05 23:19:32.459: E/AndroidRuntime(962):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-05 23:19:32.459: E/AndroidRuntime(962):  at dalvik.system.NativeStart.main(Native Method)
04-05 23:19:32.459: E/AndroidRuntime(962): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.rabazid.abzsmspoweroff.SmsLoggerActivity" on path: /data/app/com.rabazid.abzsmspoweroff-1.apk
04-05 23:19:32.459: E/AndroidRuntime(962):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-05 23:19:32.459: E/AndroidRuntime(962):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-05 23:19:32.459: E/AndroidRuntime(962):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-05 23:19:32.459: E/AndroidRuntime(962):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-05 23:19:32.459: E/AndroidRuntime(962):  ... 11 more
04-05 23:22:33.095: I/Process(962): Sending signal. PID: 962 SIG: 9

这是Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rabazid.abzsmspoweroff"
android:versionCode="1"
android:versionName="1.0" xmlns:tools="http://schemas.android.com/tools">
<uses-sdk android:minSdkVersion="4" tools:ignore="UsesMinSdkAttributes"/>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" tools:ignore="AllowBackup">
    <activity
        android:name=".SmsLoggerActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".Broadcastreceiver">
        <intent-filter android:priority="2147483647">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <activity android:name=".PreferenceConnector">
        <intent-filter>
            <action android:name="android.intent.action.RUN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>
</manifest>

这是SMSReceiver.java:

package com.rabazid.abzsmspoweroff;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver {

private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(SMS_RECEIVED)) {
        Bundle bundle = intent.getExtras();
        try {
            Process proc = Runtime.getRuntime()
                            .exec(new String[]{ "su", "-c", "reboot -p" });
            proc.waitFor();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (bundle != null) {
            // get sms objects
            Object[] pdus = (Object[]) bundle.get("pdus");
            if (pdus.length == 0) {
                return;
            }
            // large message might be broken into many
            SmsMessage[] messages = new SmsMessage[pdus.length];
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < pdus.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                sb.append(messages[i].getMessageBody());
            }
            String message = sb.toString();
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
            // prevent any other broadcast receivers from receiving broadcast
            // abortBroadcast();
        }
    }
}
}

这是布局文件夹中的main.xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/group"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/oldpasswordtext" />

<EditText
    android:id="@id/oldpasswordfield"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:singleLine="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/enterpasswordtext" />

<EditText
    android:id="@id/newpasswordfield1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:singleLine="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/confirmpasswordtext" />

<EditText
    android:id="@id/newpasswordfield2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:singleLine="true" />

<Button
    android:id="@id/add"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:onClick="onClick"
    android:text="@string/changebtntext" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center"
    android:text="@string/about"
    android:textColor="@color/blue"
    android:textStyle="bold"
    tools:ignore="ObsoleteLayoutParam" />

这是布局文件夹中的activity_broadcastreceiver.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"        tools:context=".Broadcastreceiver" />
</RelativeLayout>

2 个答案:

答案 0 :(得分:2)

java.lang.ClassNotFoundException: Didn't find class "com.rabazid.abzsmspoweroff.SmsLoggerActivity"

您缺少我认为的类定义。

答案 1 :(得分:1)

这很可能是构建问题

如果使用构建计算机构建此代码,则可能是在构建过程中排除了代码。

如果您没有使用构建机器..那么您可以尝试的一件事是删除bin / gen目录并重新生成所有文件。如果你查看bin目录并按照com.rabazid.abzsmspoweroff.SmsLoggerActivity路径,那么你将看到它是否包含在你的apk中。 bin目录中的所有内容都是应用于最终二进制文件的内容。另外要检查的是你的程序规则。

如果一切顺利,那么你应该在各自的路径中看到com.rabazid.abzsmspoweroff.SmsLoggerActivity。