0

I made an app in eclipse and it keeps on crashing every time i want to open it.The app is supposed to be able to make the phone turn off when a specifically worded text message is received.It does require root privileges.Also the way i am running it is by pressing the run button on eclipse,and it show that i have no error in the coding so as you can see i am very lost.

Here is the log file:

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

Here is the 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>

Here is the 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();
        }
    }
}
}

Here is the main.xml file inside the layout folder:

<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" />

Here is the activity_broadcastreceiver.xml file inside the layout folder:

<?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>
Kara
  • 6,115
  • 16
  • 50
  • 57
  • possible duplicate of [My app keeps on crashing](http://stackoverflow.com/questions/15844914/my-app-keeps-on-crashing) – JoxTraex Apr 05 '13 at 23:37
  • sorry didnt notice i deleted the other can any of you help me? – user2250077 Apr 05 '13 at 23:40
  • 3
    How do you not notice you posted the same large chunk of code and XML twice? You posted a couple of hundred lines in each place - pretty hard not to notice you're doing that, isn't it? :-) – Ken White Apr 05 '13 at 23:44
  • i thought i was editing the other one but i wasnt becuz i copied and pasted my log file – user2250077 Apr 05 '13 at 23:46

2 Answers2

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

You are missing the Class definition I assume.

Swayam
  • 16,294
  • 14
  • 64
  • 102
1

This is most likely a build problem

If you are building this code using a build machine then chances are that the code is being excluded in the build process.

If you are not using a build machine.. then one thing you can try is delete the bin/gen directory and regenerate all the files. If you look in the bin directory and follow the com.rabazid.abzsmspoweroff.SmsLoggerActivity path, then you will see if its being included in your apk. Everything in the bin directory is what is used applied to the final binary. Also another thing to check would be your proguard rules.

If all is well then, then you should see com.rabazid.abzsmspoweroff.SmsLoggerActivity in its respective path.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • nope i dont have the sms loggeractivity path do you know how i can add it? – user2250077 Apr 05 '13 at 23:51
  • You need to find out why its not appearing. Ideally the ADT tools should be compiling your classes into binaries and then throwing them in bin in their respective folder. Check the package name of that class and ensure that it matches the reference. If you could post the top part of your SmsLoggerActivity. – JoxTraex Apr 05 '13 at 23:55
  • @JoxTraex : I have a feeling that he hasn't defined his Activity class in java. – Swayam Apr 05 '13 at 23:57
  • Looking at the manifest, I do see the refference to SmsLoggerActivity @swayam – JoxTraex Apr 05 '13 at 23:58
  • Yeah, I know. That is why I said "in java". Look at the comments on my answer. I don't think he has a proper SmsLoggerActivity. Could have just entered the name of the Activity during the creation of the project. – Swayam Apr 06 '13 at 00:00
  • all i have is SMSReceiver.java in there – user2250077 Apr 06 '13 at 00:03
  • we are talking about SmsLoggerActivity not SMSReceiever. But yes, that could be possible, you may not have the SmsLoggerActivity java file, if thats the case then thats why its not generating that class file. – JoxTraex Apr 06 '13 at 00:04
  • 1
    @JoxTraex : He only has the SMSReceiver. That is why the Activity is not found. – Swayam Apr 06 '13 at 00:05
  • so how can i make a SmsLoggerActivity java file? – user2250077 Apr 06 '13 at 00:05
  • Make an activity file that is called SmsLoggerActivity. – JoxTraex Apr 06 '13 at 00:08
  • ok so i added it,now another question in my code where do i type the keyword that makes the phone turn off? – user2250077 Apr 06 '13 at 00:27