• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Getting error when adding widget

Feb 20, 2012
49
1
Code:
06-26 14:28:07.557: W/dalvikvm(244): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-26 14:28:07.557: E/AndroidRuntime(244): Uncaught handler: thread main exiting due to uncaught exception
06-26 14:28:07.557: E/AndroidRuntime(244): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.danielholst.batterywidgetz/com.danielholst.batterywidgetz.Setup}: java.lang.NullPointerException
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.os.Looper.loop(Looper.java:123)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.ActivityThread.main(ActivityThread.java:4363)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at java.lang.reflect.Method.invokeNative(Native Method)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at java.lang.reflect.Method.invoke(Method.java:521)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at dalvik.system.NativeStart.main(Native Method)
06-26 14:28:07.557: E/AndroidRuntime(244): Caused by: java.lang.NullPointerException
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at com.danielholst.batterywidgetz.Setup.<init>(Setup.java:21)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at java.lang.Class.newInstanceImpl(Native Method)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at java.lang.Class.newInstance(Class.java:1479)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-26 14:28:07.557: E/AndroidRuntime(244): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
06-26 14:28:07.557: E/AndroidRuntime(244): 	... 11 more
06-26 14:28:07.567: I/dalvikvm(244): threadid=7: reacting to signal 3
06-26 14:28:07.567: E/dalvikvm(244): Unable to open stack trace file '/data/anr/traces.txt': Permission denied



i have no idea why i get these errors,
but it happends right when i add the widget, i believe i might have something to do with the settings activity,

it used to work, but then suddenly stops working...

thx in advance
 
where do you see which line it is?
btw here's the code for Setup.java

Code:
package com.danielholst.batterywidgetz;

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

public class Setup extends Activity implements OnClickListener {

	
	RadioGroup main_color, text_color, style;
	AppWidgetManager awm;
	int awID;
	// Setup RemoteView For Widget
	RemoteViews Rview = new RemoteViews(Setup.this.getPackageName(),R.layout.widget);
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		/** Define objects */
		Button b_finish = (Button) findViewById(R.id.b_finish);
		b_finish.setOnClickListener(this);
		main_color = (RadioGroup) findViewById(R.id.main_color);
		text_color = (RadioGroup) findViewById(R.id.text_color);
		style = (RadioGroup) findViewById(R.id.style);
		/** End Definitions */

		// Which Widget is Being Set-up ?
		Intent which = getIntent();
		Bundle extras = which.getExtras();
		if (extras != null) {
			awID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
					AppWidgetManager.INVALID_APPWIDGET_ID);
		} else {
			finish();
		}
		awm = AppWidgetManager.getInstance(Setup.this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

		// Update Widget
		awm.updateAppWidget(awID, Rview);
		Intent result = new Intent();
		result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID);
		setResult(RESULT_OK, result);
		// Finish Setup
		finish();
	}

}
 
Upvote 0
In the log cat output you posted, there is a line that says "Caused by NullPointerException" and then under that, you look for your package name and next to it, it says "(Setup.java:21)"

As for what's wrong, you must have changed something since you posted the logcat, as line 21 is a comment.

Also, Rview should not be initialized outside of onCreate(). That honestly might be what is causing your problem.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones