[SOLVED] Custom view causes class not found exception

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

[SOLVED] Custom view causes class not found exception

Postby kahriboo » Tue Feb 09, 2010 11:46 pm

Hi all !

I'm new here and I'm having trouble with custom view.

Here my project files :
Image

With :

MyView.java(my very basic custom view...) :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.kahriboo.widget;
  2.  
  3.  
  4.  
  5. import android.content.Context;
  6.  
  7. import android.view.View;
  8.  
  9.  
  10.  
  11. public class MyView extends View {
  12.  
  13.  
  14.  
  15.         public MyView(Context context) {
  16.  
  17.                 super(context);
  18.  
  19.         }
  20.  
  21. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


MyWidget.java :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.kahriboo.widget;
  2.  
  3.  
  4.  
  5. import android.appwidget.AppWidgetManager;
  6.  
  7. import android.appwidget.AppWidgetProvider;
  8.  
  9. import android.content.Context;
  10.  
  11. import android.widget.RemoteViews;
  12.  
  13.  
  14.  
  15. public class MyWidget extends AppWidgetProvider {
  16.  
  17.  
  18.  
  19.         public void onUpdate(Context context, AppWidgetManager appWidgetManager,
  20.  
  21.                         int[] appWidgetIds) {
  22.  
  23.                
  24.  
  25.                 // Build the widget update for today
  26.  
  27.                 // Didn't find word of day, so show error message
  28.  
  29.                 RemoteViews updateViews = new RemoteViews(context.getPackageName(),
  30.  
  31.                                 R.layout.my_widget);
  32.  
  33.  
  34.  
  35.                 // Push update for this widget to the home screen
  36.  
  37.                 appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
  38.  
  39.         }
  40.  
  41.  
  42.  
  43. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



layout/my_widget.xml :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4.  
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.    android:orientation="vertical"
  8.  
  9.    android:layout_width="fill_parent"
  10.  
  11.    android:layout_height="fill_parent"
  12.  
  13.    >
  14.  
  15. <com.kahriboo.widget.MyView  
  16.  
  17.    android:layout_width="fill_parent"
  18.  
  19.    android:layout_height="wrap_content"
  20.  
  21.    />
  22.  
  23. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


xml/my_widget.xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4.  
  5. <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.    android:minWidth="146dip"
  8.  
  9.    android:minHeight="72dip"
  10.  
  11.    android:updatePeriodMillis="86400000"
  12.  
  13.    android:initialLayout="@layout/my_widget"
  14.  
  15.    />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


And manifest :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.    package="com.kahriboo.widget"
  4.  
  5.    android:versionCode="1"
  6.  
  7.    android:versionName="1.0">
  8.  
  9.  
  10.  
  11.     <application android:icon="@drawable/app_icon" android:label="@string/widget_name">
  12.  
  13.        
  14.  
  15.         <!-- Broadcast Receiver that will process AppWidget updates -->
  16.  
  17.         <receiver android:name=".MyWidget" android:label="@string/widget_name">
  18.  
  19.             <intent-filter>
  20.  
  21.                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
  22.  
  23.             </intent-filter>
  24.  
  25.             <meta-data android:name="android.appwidget.provider" android:resource="@xml/my_widget" />
  26.  
  27.         </receiver>
  28.  
  29.                
  30.  
  31.     </application>
  32.  
  33.    
  34.  
  35.     <uses-sdk android:minSdkVersion="5" />
  36.  
  37.    
  38.  
  39. </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


But when I try to deploy the widget and when putting it on the screen It say that a problem occured during the loading and in the logcat I got :

W/InputManagerService( 74): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClie
nt$Stub$Proxy@449e7178
W/AppWidgetHostView( 130): updateAppWidget couldn't find any view, using error view
W/AppWidgetHostView( 130): android.view.InflateException: Binary XML file line #8: Error inflating class com.kahriboo.w
idget.MyView
W/AppWidgetHostView( 130): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
W/AppWidgetHostView( 130): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
W/AppWidgetHostView( 130): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
W/AppWidgetHostView( 130): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
W/AppWidgetHostView( 130): at android.widget.RemoteViews.apply(RemoteViews.java:900)
W/AppWidgetHostView( 130): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:208)
W/AppWidgetHostView( 130): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:217)
W/AppWidgetHostView( 130): at com.android.launcher2.Launcher.completeAddAppWidget(Launcher.java:744)
W/AppWidgetHostView( 130): at com.android.launcher2.Launcher.onActivityResult(Launcher.java:387)
W/AppWidgetHostView( 130): at com.android.launcher2.Launcher.addAppWidget(Launcher.java:1122)
W/AppWidgetHostView( 130): at com.android.launcher2.Launcher.onActivityResult(Launcher.java:384)
W/AppWidgetHostView( 130): at android.app.Activity.dispatchActivityResult(Activity.java:3828)
W/AppWidgetHostView( 130): at android.app.ActivityThread.deliverResults(ActivityThread.java:3325)
W/AppWidgetHostView( 130): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3371)
W/AppWidgetHostView( 130): at android.app.ActivityThread.access$2700(ActivityThread.java:119)
W/AppWidgetHostView( 130): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1893)
W/AppWidgetHostView( 130): at android.os.Handler.dispatchMessage(Handler.java:99)
W/AppWidgetHostView( 130): at android.os.Looper.loop(Looper.java:123)
W/AppWidgetHostView( 130): at android.app.ActivityThread.main(ActivityThread.java:4363)
W/AppWidgetHostView( 130): at java.lang.reflect.Method.invokeNative(Native Method)
W/AppWidgetHostView( 130): at java.lang.reflect.Method.invoke(Method.java:521)
W/AppWidgetHostView( 130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
W/AppWidgetHostView( 130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
W/AppWidgetHostView( 130): at dalvik.system.NativeStart.main(Native Method)
W/AppWidgetHostView( 130): Caused by: java.lang.ClassNotFoundException: com.kahriboo.widget.MyView in loader dalvik.sys
tem.PathClassLoader@4001b4f8
W/AppWidgetHostView( 130): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
W/AppWidgetHostView( 130): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
W/AppWidgetHostView( 130): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
W/AppWidgetHostView( 130): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
W/AppWidgetHostView( 130): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
W/AppWidgetHostView( 130): ... 23 more


But the class name seems good and is present in the APK file... so what do I wrong ?

Thanks

Kahriboo
Last edited by kahriboo on Fri Feb 12, 2010 9:47 am, edited 2 times in total.
kahriboo
Freshman
Freshman
 
Posts: 4
Joined: Tue Feb 09, 2010 11:32 pm

Top

Postby kahriboo » Wed Feb 10, 2010 12:24 am

Hi again... I changed my class widget with a standard activity one :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class SimpleActivity  extends Activity {
  2.  
  3.  
  4.  
  5.         @Override
  6.  
  7.         protected void onCreate(Bundle savedInstanceState) {
  8.  
  9.                 super.onCreate(savedInstanceState);
  10.  
  11.                 setContentView(R.layout.my_widget);
  12.  
  13.         }
  14.  
  15. }
  16.  
  17.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


And so my manifest comes to :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.kahriboo.widget"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0">
  11.  
  12.     <application android:icon="@drawable/app_icon" android:label="@string/widget_name">
  13.  
  14.         <activity android:name=".SimpleActivity"
  15.  
  16.                  android:label="@string/widget_name">
  17.  
  18.             <intent-filter>
  19.  
  20.                 <action android:name="android.intent.action.MAIN" />
  21.  
  22.                 <category android:name="android.intent.category.LAUNCHER" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </activity>
  27.  
  28.  
  29.  
  30.     </application>
  31.  
  32.     <uses-sdk android:minSdkVersion="5" />
  33.  
  34.  
  35.  
  36. </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


And now it's work !

But I want to create a widget not an application ... so how do I use custom views with widget ?
Last edited by kahriboo on Fri Feb 12, 2010 9:48 am, edited 1 time in total.
kahriboo
Freshman
Freshman
 
Posts: 4
Joined: Tue Feb 09, 2010 11:32 pm

Postby kahriboo » Wed Feb 10, 2010 9:39 am

Humm... still alone :cry:

I found this : http://osdir.com/ml/Android-Developers/2009-11/msg01936.html

Question : how can a widget use my own custom View ? (same problem as me)
Answer : You cannot use custom Views in app widgets.

So maybe it's impossible ... I'll continue my investigations...
Last edited by kahriboo on Fri Feb 12, 2010 9:48 am, edited 1 time in total.
kahriboo
Freshman
Freshman
 
Posts: 4
Joined: Tue Feb 09, 2010 11:32 pm

Postby kahriboo » Wed Feb 10, 2010 11:12 am

So I've got the answer finnally ... It's impossible !

Reto Meier wrote:Unfortunately that's correct - due to security concerns you only include a limited subset of standard Views within your Homescreen Widgets.


:cry:

See ya...
kahriboo
Freshman
Freshman
 
Posts: 4
Joined: Tue Feb 09, 2010 11:32 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 12 guests