2013-10-06 114 views
2

我創建一個組件,但是當我運行它,我得到這個錯誤在控制檯:了java.lang.RuntimeException:無法實例活動ComponentInfo

[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] ------------------------------ 
[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] Android Launch! 
[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] adb is running normally. 
[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] No Launcher activity found! 
[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] The launch will only sync the application package on the device! 
[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] Performing sync 
[2013-10-05 22:02:56 - AwesomeFileBuilderWidget] Automatic Target Mode: Unable to detect device compatibility. Please select a target device. 
[2013-10-05 22:03:00 - AwesomeFileBuilderWidget] Uploading AwesomeFileBuilderWidget.apk onto device 'HT18YMA05067' 
[2013-10-05 22:03:00 - AwesomeFileBuilderWidget] Installing AwesomeFileBuilderWidget.apk... 
[2013-10-05 22:03:04 - AwesomeFileBuilderWidget] Success! 
[2013-10-05 22:03:04 - AwesomeFileBuilderWidget] \AwesomeFileBuilderWidget\bin\AwesomeFileBuilderWidget.apk installed on device 
[2013-10-05 22:03:04 - AwesomeFileBuilderWidget] Done! 

但小部件安裝設備上精細顯示出來在小工具選擇屏幕中。

當我嘗試將我的小部件放在主屏幕上時發生第二個錯誤。我得到的logcat此錯誤:

10-05 21:51:45.485: D/AndroidRuntime(3557): Shutting down VM 
10-05 21:51:45.485: W/dalvikvm(3557): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0) 
10-05 21:51:45.505: E/AndroidRuntime(3557): FATAL EXCEPTION: main 
10-05 21:51:45.505: E/AndroidRuntime(3557): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.awesomefilebuilderwidget/com.example.awesomefilebuilderwidget.WidgetConfig}: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.WidgetConfig in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk] 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1746) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:1854) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.ActivityThread.access$1500(ActivityThread.java:135) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1041) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.os.Looper.loop(Looper.java:150) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.ActivityThread.main(ActivityThread.java:4333) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at java.lang.reflect.Method.invoke(Method.java:507) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at dalvik.system.NativeStart.main(Native Method) 
10-05 21:51:45.505: E/AndroidRuntime(3557): Caused by: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.WidgetConfig in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk] 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.Instrumentation.newActivity(Instrumentation.java:1040) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1738) 
10-05 21:51:45.505: E/AndroidRuntime(3557):  ... 11 more 

這裏是我的清單:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.awesomefilebuilderwidget" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
android:minSdkVersion="8" 
android:targetSdkVersion="18" /> 

<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 

<receiver android:name=".AFBWidget" android:label="@string/app_name"> 
<intent-filter> 
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> 
</intent-filter> 

<meta-data android:name="android.appwidget.provider" 
android:resource="@xml/widget_stuff"/> 

</receiver> 

<activity android:name=".WidgetConfig" android:label="@string/app_name"> 
<intent-filter> 
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/> 
<category android:name="android.intent.category.LAUNCHER" />  
</intent-filter> 

</activity> 

<activity android:name=".AFBWidget" android:label="@string/app_name"/> 


</application> 

</manifest> 

我已經確定我已經在訂單和出口部分檢查了所有的箱子。我也確保我的AFBWidget和WidgetConfig類在src中。 (請注意,實際的小部件配置位於正確的xml位置,WidgetConfig.java是別的)

這是什麼問題?

更新的logcat:

10-05 22:47:40.628: D/AndroidRuntime(4113): Shutting down VM 
10-05 22:47:40.628: W/dalvikvm(4113): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0) 
10-05 22:47:40.638: E/AndroidRuntime(4113): FATAL EXCEPTION: main 
10-05 22:47:40.638: E/AndroidRuntime(4113): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.awesomefilebuilderwidget/com.example.awesomefilebuilderwidget.WidgetConfig}: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.WidgetConfig in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk] 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1746) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1854) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.ActivityThread.access$1500(ActivityThread.java:135) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1041) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.os.Looper.loop(Looper.java:150) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.ActivityThread.main(ActivityThread.java:4333) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at java.lang.reflect.Method.invoke(Method.java:507) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at dalvik.system.NativeStart.main(Native Method) 
10-05 22:47:40.638: E/AndroidRuntime(4113): Caused by: java.lang.ClassNotFoundException: com.example.awesomefilebuilderwidget.WidgetConfig in loader dalvik.system.PathClassLoader[/data/app/com.example.awesomefilebuilderwidget-1.apk] 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.Instrumentation.newActivity(Instrumentation.java:1040) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1738) 
10-05 22:47:40.638: E/AndroidRuntime(4113):  ... 11 more 

添加的類和XML文件: AFBWidget.java:

import java.util.Random; 

import com.example.awesomefilebuilderwidget.R; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.widget.RemoteViews; 
import android.widget.Toast; 


public class AFBWidget extends AppWidgetProvider{ 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
     int[] appWidgetIds) { 
    // TODO Auto-generated method stub 
    super.onUpdate(context, appWidgetManager, appWidgetIds); 
    Random r = new Random(); 
    int randomInt = r.nextInt(1000000000); 
    String rand = String.valueOf(randomInt); 

    final int N = appWidgetIds.length; 

    for (int i = 0; i < N; i++){ 
     int awID = appWidgetIds[i]; 
     RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.widget); 
     v.setTextViewText(R.id.tvwidgetUpdate, rand); 
     appWidgetManager.updateAppWidget(awID, v); 
    } 

} 

WidgetConfig.java:

import android.app.Activity; 
import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.RemoteViews; 

import com.example.awesomefilebuilderwidget.R; 


public class WidgetConfig extends Activity implements OnClickListener{ 

EditText info; 
AppWidgetManager awm; 
Context c; 
int awID; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.widgetconfig); 
    Button b = (Button)findViewById(R.id.bwidgetconfig); 
    b.setOnClickListener(this); 
    c = WidgetConfig.this; 
    info = (EditText)findViewById(R.id.etwidgetconfig); 
    //Getting info about the widget that launched this Activity 
    Intent i = getIntent(); 
    Bundle extras = i.getExtras(); 
    if (extras != null){ 
     awID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, 
       AppWidgetManager.INVALID_APPWIDGET_ID 
       ); 
    }else{ 
     finish(); 
    } 
    awm = AppWidgetManager.getInstance(c); 
} 

@Override 
public void onClick(View v) { 
    // TODO Auto-generated method stub 
    String e = info.getText().toString(); 

    RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget); 
    views.setTextViewText(R.id.tvConfigInput, e); 

    Intent in = new Intent(c, WidgetConfig.class); 
    PendingIntent pi = PendingIntent.getActivity(c, 0, in, 0); 
    views.setOnClickPendingIntent(R.id.bwidgetOpen, pi); 

    awm.updateAppWidget(awID, views); 

    Intent result = new Intent(); 
    result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID); 
    setResult(RESULT_OK, result); 

    finish(); 
} 


} 

Widget.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/tvConfigInput" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

<Button 
    android:id="@+id/bwidgetOpen" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

<TextView 
    android:id="@+id/tvwidgetUpdate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

</LinearLayout> 

WidgetConfig.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<EditText 
    android:id="@+id/etwidgetconfig" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="@string/user_input_application_name"> 

    <requestFocus /> 
</EditText> 

<Button 
    android:id="@+id/bwidgetconfig" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/ok" /> 

</LinearLayout> 

應用控件提供者(app_stuff.xml): enter image description here

回答

2

我終於修好了後3天!好的,所以確實是因爲我的兩個java類都在默認包中。所以要解決這個問題,因爲我的類是通過一個不同的包來訪問的,所以我創建了一個新的包,它是我的應用(com.example.awesomefilebuilderwidget),然後將這些類移到那裏,現在它可以正常工作了! :DD感謝你所做的一切,我真的做到了! - user1628978

1

嘗試清潔您的工作空間。轉到Project-> Clean並選擇您的項目。出於某種原因,eclipse不會自動生成清單。

,並嘗試通過做右擊,然後清潔

+0

我同時清理並重新啓動eclipse,然後再次清理。我還確保我完全重新將我的小部件重新安裝到我的設備上,方法是將其卸載,然後在運行我的小部件時將eclipse重新粘貼,但仍然會出現相同的錯誤。 – user1628978

+0

如果您使用的是第三方jar,是否將它們添加到庫文件夾中去Properties/Java Build Path/Libraries/Add External JARs。 – ankit

+0

我還沒有將任何外部JAR添加到項目中,除了原始的android以外不需要使用任何外部JAR。罐子我的課在這一點上 – user1628978

1

清理你的服務器在SRC添加所有活動AndroidManifest.xml.clean,然後運行項目

+0

我WidgetConfig.java和AFBWidget.java是唯一的班我除了XML文件,並在該Appwidget提供商此刻所以我應該把它們都在清單 – user1628978

+0

我希望它WidgetConfig單獨的權利,而不是我的WidgetConfig.java(包括我) – user2819836

+0

權只是「WidgetConfig」 – user1628978

相關問題