正在制作" Shortcut"小部件.. 当我在模拟器上部署它时 它说"不幸的是Shortcutter已经停止"
当我在我的暴徒设备上尝试时...它说"应用程序未安装"
Log Cat Trace:
07-16 10:03:24.686: I/Process(669): Sending signal. PID: 669 SIG: 9
07-16 10:03:47.786: D/AndroidRuntime(742): Shutting down VM
07-16 10:03:47.846: W/dalvikvm(742): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-16 10:03:47.896: E/AndroidRuntime(742): FATAL EXCEPTION: main
07-16 10:03:47.896: E/AndroidRuntime(742): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.shortcutter/com.shortcutter.Configure}: java.lang.ClassNotFoundException: com.shortcutter.Configure
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.os.Looper.loop(Looper.java:137)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-16 10:03:47.896: E/AndroidRuntime(742): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 10:03:47.896: E/AndroidRuntime(742): at java.lang.reflect.Method.invoke(Method.java:511)
07-16 10:03:47.896: E/AndroidRuntime(742): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-16 10:03:47.896: E/AndroidRuntime(742): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-16 10:03:47.896: E/AndroidRuntime(742): at dalvik.system.NativeStart.main(Native Method)
07-16 10:03:47.896: E/AndroidRuntime(742): Caused by: java.lang.ClassNotFoundException: com.shortcutter.Configure
07-16 10:03:47.896: E/AndroidRuntime(742): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-16 10:03:47.896: E/AndroidRuntime(742): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-16 10:03:47.896: E/AndroidRuntime(742): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
07-16 10:03:47.896: E/AndroidRuntime(742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
07-16 10:03:47.896: E/AndroidRuntime(742): ... 11 more
MainActivity.java:
package com.shortcutter; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.view.Menu; import android.widget.RemoteViews;
public class MainActivity extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // TODO Auto-generated method stub super.onUpdate(context, appWidgetManager, appWidgetIds); for(int i=0; i<appWidgetIds.length; i++ ) { int appWidgetId = appWidgetIds[i]; Intent intent= new Intent (Intent.ACTION_VIEW, Uri.parse("http://google.com") ); PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);`` views.setOnClickPendingIntent(R.id.imageView1, pending); appWidgetManager.updateAppWidget(appWidgetId, views); }}}
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="85dp"
android:layout_height="85dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
AndroidManifest.xml:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <receiver android:name="MainActivity"> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" /> </receiver> <activity android:name=".Configure"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/> </intent-filter> </activity> </application> </manifest>
Widget.xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/activity_main" android:minWidth="144dp" android:updatePeriodMillis="0" android:minHeight="72dp" android:configure="com.shortcutter.Configure">
</appwidget-provider>
Configure.java:
import com.shortcutter.R;
import android.app.Activity;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.net.Uri;
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;
public class Configure extends Activity {
private Configure context;
private int widgetID;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.configure);
setResult(RESULT_CANCELED);
context = this;
Bundle extras = getIntent().getExtras();
if(extras != null ); {
widgetID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
final AppWidgetManager widgetManeger = AppWidgetManager.getInstance(context);
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);
final EditText et = (EditText) findViewById(R.id.editText1);
Button b = (Button)findViewById(R.id.save_button);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent (Intent.ACTION_VIEW, Uri.parse(et.getText().toString()) );
PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.imageView1, pending);
widgetManeger.updateAppWidget(widgetID, views);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetID);
setResult(RESULT_OK, resultValue);
}
});
}
}
Configure.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/pattern">
<Button
android:id="@+id/save_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Create Widget" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="21dp"
android:paddingLeft="@dimen/left"
android:text="Link: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFF"
android:textSize="20dp"
android:textStyle="bold"
android:typeface="normal" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:text="http://google.com"
android:textStyle="normal" />
</RelativeLayout>
是的,有人可以帮帮我吗? :)
顺便说一下,我还是初学者。