2013-04-05 125 views
0

我在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清單:

<?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> 
+0

可能重複的[我的應用程序不斷崩潰](http://stackoverflow.com/questions/15844914/my-app-keeps-on-crashing) – JoxTraex 2013-04-05 23:37:40

+0

不要雙重張貼。 – JoxTraex 2013-04-05 23:37:46

+0

抱歉沒有注意到我刪除了其他人可以幫助我嗎? – user2250077 2013-04-05 23:40:08

回答

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

你缺少類定義我承擔。

+0

對不起,但我不得不問。什麼是類定義,我如何添加它? – user2250077 2013-04-05 23:45:56

+0

你的'SmsLoggerActivity'在哪裏?你有沒有定義它? – Swayam 2013-04-05 23:46:47

+0

這是我得到的唯一日誌是一個和另一個,但那個擁有在系統上運行的所有內容而不是應用程序 – user2250077 2013-04-05 23:49:03

1

這很可能是一個構建問題

如果您正在構建使用構建機器,然後有機會,該代碼被排除在構建過程中的代碼。

如果您不使用生成機器,那麼您可以嘗試的一件事是刪除bin/gen目錄並重新生成所有文件。如果您查看bin目錄並按照com.rabazid.abzsmspoweroff.SmsLoggerActivity路徑,那麼您會看到它是否包含在您的apk中。 bin目錄中的所有內容都是應用於最終二進制文件的內容。另外要檢查的是你的proguard規則。

如果一切都很好,那麼你應該在其各自的路徑中看到com.rabazid.abzsmspoweroff.SmsLoggerActivity。

+0

nope我沒有短信loggeractivity路徑你知道我可以如何添加它嗎? – user2250077 2013-04-05 23:51:52

+0

你需要找出爲什麼它沒有出現。理想情況下,ADT工具應該將您的類編譯爲二進制文件,然後將它們放入相應文件夾的文件夾中。檢查該類的包名,並確保它與參考相匹配。如果你可以發佈你的SmsLoggerActivity的頂部。 – JoxTraex 2013-04-05 23:55:14

+0

@JoxTraex:我有一種感覺,他沒有在java中定義他的Activity類。 – Swayam 2013-04-05 23:57:09