je suis en train de montrer le widget simple avec seulement quelques images, et chaque fois que je tente de montrer les accidents app et je reçois une chaîne vide refrenceréférence d'objet null lorsque vous essayez de montrer un widget
Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
at java.lang.String.contains(String.java:2078)
at com.sec.location.nsflp2.a.a.c.b()
at com.sec.location.nsflp2.a.a.c.onForegroundActivitiesChanged()
at android.app.IProcessObserver$Stub.onTransact(IProcessObserver.java:55)
at android.os.Binder.execTransact(Binder.java:573)
J'ai changé toutes les chaînes et implémentations de chaînes dans le code du widget, mais cela n'aide pas.
ici est mon MainClockWidget:
public class MainClockWidget extends AppWidgetProvider {
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
CharSequence widgetText = MainClockWidgetConfigureActivity.loadTitlePref(context, appWidgetId);
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main_clock_widget);
views.setTextViewText(R.id.appwidget_text, "hellow");
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
// When the user deletes the widget, delete the preference associated with it.
for (int appWidgetId : appWidgetIds) {
MainClockWidgetConfigureActivity.deleteTitlePref(context, appWidgetId);
}
}
@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}
@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}
}
MainClockWidgetConfigureActivity:
public class MainClockWidgetConfigureActivity extends Activity {
private static final String PREFS_NAME = "layout.MainClockWidget";
private static final String PREF_PREFIX_KEY = "appwidget_";
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
EditText mAppWidgetText;
View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
final Context context = MainClockWidgetConfigureActivity.this;
// When the button is clicked, store the string locally
// String widgetText = mAppWidgetText.getText().toString();
String widgetText = "Testings String";
saveTitlePref(context, mAppWidgetId, widgetText);
// It is the responsibility of the configuration activity to update the app widget
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
MainClockWidget.updateAppWidget(context, appWidgetManager, mAppWidgetId);
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
};
public MainClockWidgetConfigureActivity() {
super();
}
// Write the prefix to the SharedPreferences object for this widget
static void saveTitlePref(Context context, int appWidgetId, String text) {
SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit();
prefs.putString(PREF_PREFIX_KEY + appWidgetId, text);
prefs.apply();
}
// Read the prefix from the SharedPreferences object for this widget.
// If there is no preference saved, get the default from a resource
static String loadTitlePref(Context context, int appWidgetId) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
String titleValue = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null);
if (titleValue != null) {
return titleValue;
} else {
return context.getString(R.string.appwidget_text);
}
}
static void deleteTitlePref(Context context, int appWidgetId) {
SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit();
prefs.remove(PREF_PREFIX_KEY + appWidgetId);
prefs.apply();
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if the user presses the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.main_clock_widget_configure);
mAppWidgetText = (EditText) findViewById(R.id.appwidget_text);
findViewById(R.id.add_button).setOnClickListener(mOnClickListener);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If this activity was started with an intent without an app widget ID, finish with an error.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
return;
}
mAppWidgetText.setText("testings");
}
}
et mon xml widget de
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/the_nightmare_widget_background_resized"
android:id="@+id/clock_background_image"
/>
<ImageView
android:layout_width="400dp"
android:layout_height="match_parent"
android:rotation="0"
android:layout_centerVertical="true"
android:id="@+id/clock_minutes_dial_image"
android:layout_centerHorizontal="true"
android:src="@drawable/the_nightmare_minute_pointer"
/>
<ImageView
android:layout_width="190dp"
android:layout_height="match_parent"
android:rotation="-5"
android:id="@+id/clock_hour_dial_image"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/the_nightmare_hour_pointer"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:id="@+id/clock_center_image"
android:layout_centerHorizontal="true"
android:src="@drawable/the_nightmare_center"
/>
<TextView
android:id="@+id/appwidget_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:background="#09C"
android:contentDescription="@string/appwidget_text"
android:text="@string/appwidget_text"
android:textColor="#ffffff"
android:textSize="24sp"
android:textStyle="bold|italic" />
</RelativeLayout>
quel pourrait être le problème?