Android setdrawable from another class - android

Here's my code. I am trying to set background of a linear layout. But this xml (rowback) is not my main activity content, so gives errors. how can I set some XML from the class which doesn't have that XML in its content?
setContentView(R.layout.activity_quick_search_products);
...
rowb = (LinearLayout)findViewById(R.id.rowback);
...
final Drawable d = getResources().getDrawable(R.drawable.denemebut3);
d.setAlpha(100);
rowb.setBackgroundDrawable(d);
Logcat:
03-30 02:52:50.822: D/AndroidRuntime(14677): Shutting down VM
03-30 02:52:50.822: W/dalvikvm(14677): threadid=1: thread exiting with uncaught exception (group=0x40c841f8)
03-30 02:52:50.822: E/AndroidRuntime(14677): FATAL EXCEPTION: main
03-30 02:52:50.822: E/AndroidRuntime(14677): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vitrinn/com.vitrinn.QuickSearchProducts}: java.lang.NullPointerException
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.os.Looper.loop(Looper.java:137)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.main(ActivityThread.java:4507)
03-30 02:52:50.822: E/AndroidRuntime(14677): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 02:52:50.822: E/AndroidRuntime(14677): at java.lang.reflect.Method.invoke(Method.java:511)
03-30 02:52:50.822: E/AndroidRuntime(14677): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
03-30 02:52:50.822: E/AndroidRuntime(14677): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
03-30 02:52:50.822: E/AndroidRuntime(14677): at dalvik.system.NativeStart.main(Native Method)
03-30 02:52:50.822: E/AndroidRuntime(14677): Caused by: java.lang.NullPointerException
03-30 02:52:50.822: E/AndroidRuntime(14677): at com.vitrinn.QuickSearchProducts.onCreate(QuickSearchProducts.java:69)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.Activity.performCreate(Activity.java:4469)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
03-30 02:52:50.822: E/AndroidRuntime(14677): ... 11 more

If R.id.rowback doesn't belong to your main activity xml resource, then you should inflate that resource manually using:
LinearLayout rowb = (LinearLayout) getLayoutInflater().inflate(XML file that contains R.id.rowback, null);
then you can safely do
rowb.setBackgroundDrawable(d);
As an extra, if you have nested elements in rowback then you can invoke:
rowb.findViewById(R.id.Something) safely.
Or if your class is not exteding from any Activity, you can always receive a Context object in its constructor, and then use
LayoutInflater.from(context)
to get a LayoutInflater object so you can inflate any XML resource you need that is not actually in your main content.
Hope this clarifies...

Related

Android Google Analytics compile error "Could not find class"

I have called:
compile 'com.google.android.gms:play-services-analytics:7.5.0'
When I run project I get an error:
Log cat :
06-26 15:39:17.563 2415-2415/com.demo E/dalvikvm﹕ Could not find class 'com.demo.utils.logger.ChainedLogNode', referenced from
method com.demo.utils.logger.Logger.initialize.
When I remove compile 'com.google.android.gms:play-services-analytics:7.5.0', it runs ok.
Stop app :
6-26 15:39:17.579 2415-2415/com.demo.app E/AndroidRuntime﹕ FATAL
EXCEPTION: main
java.lang.NoClassDefFoundError: com.demo.utils.logger.ChainedLogNode
at com.demo.utils.logger.Logger.initialize(Logger.java:150)
at com.demo.utils.CommonUtil.setupLoggers(CommonUtil.java:3215)
at com.demo.DemoApplication.onCreate(DemoApplication.java:103)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:999)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4151)
at android.app.ActivityThread.access$1300(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

App crashes when instantiating HelpStackSDK

We tried integrating HelpStack by following steps given on GitHub, but we kept getting the following errors:
04-03 13:54:22.054 4638-4638/com.playerline.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.playerline.android/com.tenmiles.helpstack.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.tenmiles.helpstack.activities.HSActivityParent.onCreate(HSActivityParent.java:48)
at com.tenmiles.helpstack.activities.HomeActivity.onCreate(HomeActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
I'm guessing it has something to do with the App Theme, which in our case is is Theme.AppCompat.NoActionBar.

Android Search Interface Tutorial

I did the first part of this tutorial...
http://developer.android.com/training/search/setup.html
I made the options_menu.xml and added the code to the onCreateOptionsMenu() method. After I run my app on my device it turns on and automatically crashes. Sorry I don't know if I formatted the LogCat message below properly but I copy / pasted into here so it may help determine what the problem is, I'm not sure how to read it or fix the issue. Let me know if I can format it more properly or maybe export other error messages if needed. Under "Problems" I have two...
the import android.os Build is never used
The import android.support.v7.app.ActionBar is never used
not sure if thats important...Thanks!
03-30 19:13:06.266: W/ApplicationPackageManager(17378): getCSCPackageItemText()
03-30 19:13:06.326: E/MoreInfoHPW_ViewGroup(17378): Parent view is not a TextView
03-30 19:13:06.436: I/Adreno-EGL(17378): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
03-30 19:13:06.436: I/Adreno-EGL(17378): OpenGL ES Shader Compiler Version: E031.24.00.07
03-30 19:13:06.436: I/Adreno-EGL(17378): Build Date: 01/22/14 Wed
03-30 19:13:06.436: I/Adreno-EGL(17378): Local Branch: base_au149_adreno_au169_patches
03-30 19:13:06.436: I/Adreno-EGL(17378): Remote Branch:
03-30 19:13:06.436: I/Adreno-EGL(17378): Local Patches:
03-30 19:13:06.436: I/Adreno-EGL(17378): Reconstruct Branch:
03-30 19:13:06.466: D/OpenGLRenderer(17378): Enabling debug mode 0
03-30 19:13:06.496: W/ResourceType(17378): getEntry failing because entryIndex 1 is beyond type entryCount 1
03-30 19:13:06.496: W/ResourceType(17378): Failure getting entry for 0x7f0c0001 (t=11 e=1) in package 0 (error -2147483647)
03-30 19:13:06.496: D/AndroidRuntime(17378): Shutting down VM
03-30 19:13:06.496: W/dalvikvm(17378): threadid=1: thread exiting with uncaught exception (group=0x417adda0)
03-30 19:13:06.506: E/AndroidRuntime(17378): FATAL EXCEPTION: main
03-30 19:13:06.506: E/AndroidRuntime(17378): Process: com.example.csbizsearch, PID: 17378
03-30 19:13:06.506: E/AndroidRuntime(17378): android.content.res.Resources$NotFoundException: Resource ID #0x7f0c0001
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.content.res.Resources.getValue(Resources.java:2009)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.content.res.Resources.loadXmlResourceParser(Resources.java:3224)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.content.res.Resources.getLayout(Resources.java:1825)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:115)
03-30 19:13:06.506: E/AndroidRuntime(17378): at com.example.csbizsearch.MainActivity.onCreateOptionsMenu(MainActivity.java:30)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.app.Activity.onCreatePanelMenu(Activity.java:2588)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
03-30 19:13:06.506: E/AndroidRuntime(17378): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:486)
03-30 19:13:06.506: E/AndroidRuntime(17378): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:855)
03-30 19:13:06.506: E/AndroidRuntime(17378): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:271)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.view.Choreographer.doCallbacks(Choreographer.java:603)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.view.Choreographer.doFrame(Choreographer.java:572)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.os.Handler.handleCallback(Handler.java:733)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.os.Handler.dispatchMessage(Handler.java:95)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.os.Looper.loop(Looper.java:157)
03-30 19:13:06.506: E/AndroidRuntime(17378): at android.app.ActivityThread.main(ActivityThread.java:5293)
03-30 19:13:06.506: E/AndroidRuntime(17378): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 19:13:06.506: E/AndroidRuntime(17378): at java.lang.reflect.Method.invoke(Method.java:515)
03-30 19:13:06.506: E/AndroidRuntime(17378): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-30 19:13:06.506: E/AndroidRuntime(17378): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-30 19:13:06.506: E/AndroidRuntime(17378): at dalvik.system.NativeStart.main(Native Method)
03-30 19:13:09.836: I/Process(17378): Sending signal. PID: 17378 SIG: 9
I've havent got this error in Android Studio so I will continue to use this instead of eclipse...If anyone finds the a solution to this that would be great though!!

Phonegap Android facebook plugin crashes

I am getting the error below when I try to login through facebook plugin for Android.
The app basically crashes "stopped", Any ideas will be appreciated.
ERROR/AndroidRuntime(2008): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {xxx/com.facebook.LoginActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x7f060012
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f060012
at android.content.res.Resources.getText(Resources.java:230)
at android.content.res.Resources.getString(Resources.java:314)
at android.content.Context.getString(Context.java:327)
at com.facebook.widget.WebDialog.onCreate(WebDialog.java:189)
at android.app.Dialog.dispatchOnCreate(Dialog.java:355)
at android.app.Dialog.show(Dialog.java:260)
at com.facebook.AuthorizationClient$WebViewAuthHandler.tryAuthorize(AuthorizationClient.java:471)
at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:214)
at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:193)
at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:121)
at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:102)
at com.facebook.LoginActivity.onResume(LoginActivity.java:113)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
at android.app.Activity.performResume(Activity.java:5182)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
... 12 more
i kinda resolved it, i deleted the app_id string. turns out facebook plugin doesn't use that.

Android app crashes as i try to use kSoap2

Hi im new to Android development.. Sorry.
My Android App crashes as i am trying to use kSoap2 to connect the app to a web service:
My Error log is as follows:
2-05 12:48:05.100: E/dalvikvm(749): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.example.mytestws.MainActivity.onCreate
12-05 12:48:05.100: W/dalvikvm(749): VFY: unable to resolve new-instance 548 (Lorg/ksoap2/serialization/SoapObject;) in Lcom/example/mytestws/MainActivity;
12-05 12:48:05.100: D/dalvikvm(749): VFY: replacing opcode 0x22 at 0x0012
12-05 12:48:05.100: D/dalvikvm(749): VFY: dead code 0x0014-0057 in Lcom/example/mytestws/MainActivity;.onCreate (Landroid/os/Bundle;)V
12-05 12:48:05.250: D/AndroidRuntime(749): Shutting down VM
12-05 12:48:05.250: W/dalvikvm(749): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-05 12:48:05.261: E/AndroidRuntime(749): FATAL EXCEPTION: main
12-05 12:48:05.261: E/AndroidRuntime(749): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
12-05 12:48:05.261: E/AndroidRuntime(749): at com.example.mytestws.MainActivity.onCreate(MainActivity.java:29)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.os.Looper.loop(Looper.java:123)
12-05 12:48:05.261: E/AndroidRuntime(749): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-05 12:48:05.261: E/AndroidRuntime(749): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 12:48:05.261: E/AndroidRuntime(749): at java.lang.reflect.Method.invoke(Method.java:521)
12-05 12:48:05.261: E/AndroidRuntime(749): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-05 12:48:05.261: E/AndroidRuntime(749): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-05 12:48:05.261: E/AndroidRuntime(749): at dalvik.system.NativeStart.main(Native Method)
You have to add ksoap2 library to your classpath as an external library and also copy the .jar into libs folder of the project.

Categories

Resources