I am starting in the widget for android world. I have this layout, named "widget.xml":
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip" >
<ImageButton
android:id="#+id/icono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
It simply a button, as you can see. This is the configuration xml of the widget:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="#layout/widget"
android:minWidth="72dip"
android:minHeight="72dip"
android:updatePeriodMillis="7000"
android:label="Widget_azafata"
/>
This is the class extending AppWidgetProvider, as is, it is untouched:
public class WidgetAppProvider extends AppWidgetProvider{
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
And this is the configuration Activity:
public class WidgetConfig extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
ImageButton boton=(ImageButton) findViewById(R.id.icono);
//stuff here
}
And the lines in the manifest:
<receiver
android:name=".WidgetAppProvider"
android:label="Widget_azafata">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_azafata_xml" />
</receiver>
Well, i launch the widget and shows this Exception:
05-04 10:21:14.144: E/AndroidRuntime(320): FATAL EXCEPTION: main
05-04 10:21:14.144: E/AndroidRuntime(320): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.publidirecta.Azafata/com.publidirecta.Azafata.WidgetAppProvider}: java.lang.ClassCastException: com.publidirecta.Azafata.WidgetAppProvider
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.os.Looper.loop(Looper.java:123)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-04 10:21:14.144: E/AndroidRuntime(320): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 10:21:14.144: E/AndroidRuntime(320): at java.lang.reflect.Method.invoke(Method.java:521)
05-04 10:21:14.144: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-04 10:21:14.144: E/AndroidRuntime(320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-04 10:21:14.144: E/AndroidRuntime(320): at dalvik.system.NativeStart.main(Native Method)
05-04 10:21:14.144: E/AndroidRuntime(320): Caused by: java.lang.ClassCastException: com.publidirecta.Azafata.WidgetAppProvider
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-04 10:21:14.144: E/AndroidRuntime(320): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
It shows no line of error, simply the class where the exception is launched. And i don't know why this Exception is launched. Any help would be very appreciated.
Thank you very much!
Are you declaring your Activity in manifest?
and you should switch the sequence of lines in onCreate() like this:
super.onCreate(savedInstanceState); // this should be first call
setContentView(R.layout.main);
ImageButton boton=(ImageButton) findViewById(R.id.icono);
I Think your XML name is "widget.xml", but you are calling main.xml in activity.you have to change SetContentView(R.layout.widget);
Somewhere, you are calling startActivity() to start WidgetAppProvider. WidgetAppProvider is a BroadcastReceiver, not an Activity.
Related
Made My first app. Just after creating I tried make it Full screen. It says "Unfortunately your app has been stopped."
Android manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nirmal.projectfullscreen">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActiviy.java
package com.example.nirmal.projectfullscreen;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
logcat
03-25 22:05:14.257 5289-5289/com.example.nirmal.projectfullscreen E/Trace: error opening trace file: No such file or directory (2)
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to resolve interface method 15038: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to resolve interface method 15042: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
03-25 22:05:14.437 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41f3c600)
03-25 22:05:14.437 5289-5289/com.example.nirmal.projectfullscreen E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nirmal.projectfullscreen/com.example.nirmal.projectfullscreen.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5578)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.nirmal.projectfullscreen.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5578)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: killProcess, pid=5289
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: dalvik.system.VMStack.getThreadStackTrace(Native Method)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.Thread.getStackTrace(Thread.java:599)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: android.os.Process.killProcess(Process.java:956)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:108)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: dalvik.system.NativeStart.main(Native Method)
You are using AppCompatActivity and thus your theme should inherit Theme.AppCompat.
You need to use a Theme.AppCompat theme (or descendant) with this activity.
Use this theme:
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
In your manifest:
android:theme="#style/AppFullScreenTheme"
I am trying to create an application location, but it shows me the error the application of gmaps (com.formation.gmaps) has stopped unexpectedly.
Note that I have already uninstalled eclipse but always this error appears.
Here is my Error log:
03-25 14:21:59.914: E/AndroidRuntime(431): FATAL EXCEPTION: main
03-25 14:21:59.914: E/AndroidRuntime(431): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.formation.gmaps/com.formation.gmaps.MainActivity}: java.lang.ClassNotFoundException: com.formation.gmaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.formation.gmaps-1.apk]
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.os.Looper.loop(Looper.java:123)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-25 14:21:59.914: E/AndroidRuntime(431): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 14:21:59.914: E/AndroidRuntime(431): at java.lang.reflect.Method.invoke(Method.java:521)
03-25 14:21:59.914: E/AndroidRuntime(431): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-25 14:21:59.914: E/AndroidRuntime(431): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-25 14:21:59.914: E/AndroidRuntime(431): at dalvik.system.NativeStart.main(Native Method)
03-25 14:21:59.914: E/AndroidRuntime(431): Caused by: java.lang.ClassNotFoundException: com.formation.gmaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.formation.gmaps-1.apk]
03-25 14:21:59.914: E/AndroidRuntime(431): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-25 14:21:59.914: E/AndroidRuntime(431): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-25 14:21:59.914: E/AndroidRuntime(431): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-25 14:21:59.914: E/AndroidRuntime(431): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
03-25 14:21:59.914: E/AndroidRuntime(431): ... 11 more
This is MainActivity.java
package com.formation.gmaps;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.maps.MapActivity;
public class MainActivity extends MapActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
This is AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.formation.gmaps.MainActivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.formation.gmaps.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The system cannot find the MainActivity.class in your com.formation.gmaps package. This can be caused by many things but you can check if:
1. You declared your activity com.formation.gmaps.MainActivity in your AndroidManifest.xml.
2. Your MainActivity.java has the correct package name set in the top of the file (e.g package com.formation.gmaps).
3. You should have import com.formation.gmaps.R;
4. Use the shortcut CTRL + SHIFT + O in Eclipse. This will import any missing classes.
5. A Project -> Clean could also help(provided you're using Eclipse).
EDIT
In your AndroidManifest.xml change package="com.formation.gmaps.MainActivity" to package="com.formation.gmaps".
EDIT 02
Your problem is your MapActivity.java. Read this. If you used the latest API then this paragraph explains it:
Because maps are encapsulated in the MapFragment class, you can
implement them by extending the Android standard Activity class,
rather than extending the MapActivity used in version 1.
So please check your MapActivity.class. If it extends Fragment then the problem is there. You can test this by changing your MainActivity to extent Activity instead of MapActivity. Do not forget to add import android.app.Activity;
If you're still using V1 of Maps then read the documentation on the link I have provided and switch to V2. You might still be using the old version which requires the process of importing a maps.jar.
This might help you as well.
Good luck and let us know if you run into more trouble.
I have been trying to add a map to my application, I have followed instructions on the android developers HelloGoogleMaps tutorial but my map is just force closing when I run the maps option. I have obtained my api key logged permissions in manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MappDemo.mymaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="true" >
<activity
android:name=".MappingDemoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<uses-library android:name="com.google.android.maps" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShowTheMap" android:label="Lat/Long Location"> </activity>
<activity android:name=".MapMe" android:label="Track Present Location"> </activity>
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</application>
</manifest>
Can some one tell if any thing needs to be configured in addition to run the code?
03-25 11:50:52.217: I/Process(687): Sending signal. PID: 687 SIG: 9
03-25 11:51:00.557: D/AndroidRuntime(729): Shutting down VM
03-25 11:51:00.567: W/dalvikvm(729): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-25 11:51:00.627: E/AndroidRuntime(729): FATAL EXCEPTION: main
03-25 11:51:00.627: E/AndroidRuntime(729): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MappDemo.mymaps/com.MappDemo.mymaps.MappingDemoActivity}: java.lang.ClassCastException: com.MappDemo.mymaps.MappingDemoActivity
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.os.Looper.loop(Looper.java:123)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-25 11:51:00.627: E/AndroidRuntime(729): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 11:51:00.627: E/AndroidRuntime(729): at java.lang.reflect.Method.invoke(Method.java:507)
03-25 11:51:00.627: E/AndroidRuntime(729): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-25 11:51:00.627: E/AndroidRuntime(729): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-25 11:51:00.627: E/AndroidRuntime(729): at dalvik.system.NativeStart.main(Native Method)
03-25 11:51:00.627: E/AndroidRuntime(729): Caused by: java.lang.ClassCastException: com.MappDemo.mymaps.MappingDemoActivity
03-25 11:51:00.627: E/AndroidRuntime(729): at com.MappDemo.mymaps.MappingDemoActivity.onCreate(MappingDemoActivity.java:19)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 11:51:00.627: E/AndroidRuntime(729): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-25 11:51:00.627: E/AndroidRuntime(729): ... 11 more
03-25 11:51:10.013: I/Process(729): Sending signal. PID: 729 SIG: 9
03-25 11:52:16.817: D/AndroidRuntime(782): Shutting down VM
03-25 11:52:16.817: W/dalvikvm(782): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-25 11:52:16.877: E/AndroidRuntime(782): FATAL EXCEPTION: main
03-25 11:52:16.877: E/AndroidRuntime(782): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MappDemo.mymaps/com.MappDemo.mymaps.MappingDemoActivity}: java.lang.ClassCastException: com.MappDemo.mymaps.MappingDemoActivity
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.os.Looper.loop(Looper.java:123)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-25 11:52:16.877: E/AndroidRuntime(782): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 11:52:16.877: E/AndroidRuntime(782): at java.lang.reflect.Method.invoke(Method.java:507)
03-25 11:52:16.877: E/AndroidRuntime(782): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-25 11:52:16.877: E/AndroidRuntime(782): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-25 11:52:16.877: E/AndroidRuntime(782): at dalvik.system.NativeStart.main(Native Method)
03-25 11:52:16.877: E/AndroidRuntime(782): Caused by: java.lang.ClassCastException: com.MappDemo.mymaps.MappingDemoActivity
03-25 11:52:16.877: E/AndroidRuntime(782): at com.MappDemo.mymaps.MappingDemoActivity.onCreate(MappingDemoActivity.java:19)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 11:52:16.877: E/AndroidRuntime(782): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-25 11:52:16.877: E/AndroidRuntime(782): ... 11 more
this is what I can see in logcat..
this what I have in mappingDemoActivity.java
public class MappingDemoActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//add listners for all buttons
View firstbutton= findViewById(R.id.geocode_button);
firstbutton.setOnClickListener((OnClickListener) this);
View secondButton = findViewById(R.id.latlong_button);
secondButton.setOnClickListener((OnClickListener) this);
View thirdButton = findViewById(R.id.presentLocation_button);
thirdButton.setOnClickListener((OnClickListener) this);
}
public void onClick(View v)
{
switch(v.getId())
{
case R.id.geocode_button:
Log.i("Button","Button 1 pushed");
Intent j = new Intent(this, ShowTheMap.class);
startActivity(j);
break;
case R.id.latlong_button:
Log.i("Button","Button 2 pushed");
Intent k = new Intent(this, ShowTheMap.class);
startActivity(k);
break;
case R.id.presentLocation_button:
Log.i("Button","Button 3 pushed");
Intent m = new Intent(this, MapMe.class);
startActivity(m);
break;
}
}
<uses-permission> tag needs to be a child of <manifest>, not <application>.
Try change <uses-permission> position, it can help.
Remove this code which is inside <intent-filter>
`<uses-library android:name="com.google.android.maps" />`
Because it is Already there in Below Quote.
Have a look at the Google MapsDemo that is included in the SDK my path is:
C:\android-sdk\add-ons\addon-google_apis-google_inc_-10\samples\MapsDemo
I had a quite anoying problem (MapActivity crashes on some devices) that was only showing up on certain(!) Android devices and also not in the Emulator. What I did was, to strip down the working demo until it was similar to my basic example. Then it turned out that Samsung phones don't accept package names not starting with com., while other devices (HTC Flyer) do! But this is not your problem, since you are using a com. package name.
There might be one more thing that comes to my mind. You didn't post your main.xml. If you use a nested LinearLayout below the MapView this also crashes the app. On top of the MapView it works fine. So in case you are using something like:
<LinearLayout ... >
<com.google.android.maps.MapView ... />
<LinearLayout ... >
<Button .../>
</LinearLayout>
</LinearLayout>
This could cause your problem. This is reproducable and throws exactly the same java.lang.ClassCastException error.
Also be sure to have your < uses-permission > and < uses-library > statements in the right place, as the guys said before. The first one must be a direct child of the < manifest > node. The second one must be a direct child of the < application > node.
I hope this helps you. I was going crazy with this stuff.
Bernd
11-10 12:07:00.327: WARN/dalvikvm(558): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): FATAL EXCEPTION: main
11-10 12:07:00.357: ERROR/AndroidRuntime(558): java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.mutmonix.series/com.mutmonix.series.Main}:
java.lang.ClassNotFoundException: com.mutmonix.series.Main in loader
dalvik.system.PathClassLoader[/data/app/com.mutmonix.series-1.apk]
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-10 12:07:00.357: ERROR/AndroidRuntime(558):
at android.os.Handler.dispatchMessage(Handler.java:99) 11-10
12:07:00.357: ERROR/AndroidRuntime(558): at
android.os.Looper.loop(Looper.java:123) 11-10 12:07:00.357:
ERROR/AndroidRuntime(558): at
android.app.ActivityThread.main(ActivityThread.java:4627) 11-10
12:07:00.357: ERROR/AndroidRuntime(558): at
java.lang.reflect.Method.invokeNative(Native Method) 11-10
12:07:00.357: ERROR/AndroidRuntime(558): at
java.lang.reflect.Method.invoke(Method.java:521) 11-10 12:07:00.357:
ERROR/AndroidRuntime(558): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 11-10
12:07:00.357: ERROR/AndroidRuntime(558): at
dalvik.system.NativeStart.main(Native Method) 11-10 12:07:00.357:
ERROR/AndroidRuntime(558): Caused by:
java.lang.ClassNotFoundException: com.mutmonix.series.Main in loader
dalvik.system.PathClassLoader[/data/app/com.mutmonix.series-1.apk]
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at
java.lang.ClassLoader.loadClass(ClassLoader.java:573) 11-10
12:07:00.357: ERROR/AndroidRuntime(558): at
java.lang.ClassLoader.loadClass(ClassLoader.java:532) 11-10
12:07:00.357: ERROR/AndroidRuntime(558): at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-10 12:07:00.357: ERROR/AndroidRuntime(558): ... 11 more 11-10
12:07:00.377: WARN/ActivityManager(68): Force finishing activity
com.mutmonix.series/.Main 11-10 12:07:00.897:
WARN/ActivityManager(68): Activity pause timeout for
HistoryRecord{45027410 com.mutmonix.series/.Main}
Main. Java
package com.mutmonix.series.activities;
import com.mutmonix.series.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class Main extends Activity implements OnClickListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.link_BlueStone).setOnClickListener(this);
}
#Override
public void onClick(View v) {
if(v.getId()==R.id.link_BlueStone){
}
}
}
Manifest File contains the code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mutmonix.series" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Main" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The reason looks fairly clear to me:
java.lang.ClassNotFoundException: com.mutmonix.series.Main
It appears that you haven't included that class in your APK. Even if you think you have, you should double check.
If you are sure you have included Main class in that, then You mus check in
AndroidManifest.xml
That com.mutmonix.series.Main class included with the correct package name.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=" com.mutmonix.series"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Main" >
I have a working Android application. It works on more than 500 different devices. The manifest is
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.decamps.droid.photoid" android:versionCode="5"
android:versionName="1.4">
<application android:icon="#drawable/icon" android:label="#string/app_label"
android:name="PhotoIDroid" android:description="#string/app_desc"
android:debuggable="FALSE">
But when it it launched from a Samsung Galaxy Tab, it doesn't start and crashes with:
java.lang.RuntimeException: Unable to
instantiate application
info.decamps.droid.photoid.PhotoIDroid:
java.lang.ClassNotFoundException:
info.decamps.droid.photoid.PhotoIDroid
in loader
dalvik.system.PathClassLoader[/data/app/info.decamps.droid.photoid-1.apk]
at
android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:670)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4483)
at
android.app.ActivityThread.access$3000(ActivityThread.java:135)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2181)
at
android.os.Handler.dispatchMessage(Handler.java:99)
at
android.os.Looper.loop(Looper.java:144)
at
android.app.ActivityThread.main(ActivityThread.java:4937)
at
java.lang.reflect.Method.invokeNative(Native
Method) at
java.lang.reflect.Method.invoke(Method.java:521)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at
dalvik.system.NativeStart.main(Native
Method) Caused by:
java.lang.ClassNotFoundException:
info.decamps.droid.photoid.PhotoIDroid
in loader
dalvik.system.PathClassLoader[/data/app/info.decamps.droid.photoid-1.apk]
at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at
android.app.Instrumentation.newApplication(Instrumentation.java:945)
at
android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:660)
... 11 more
How an the Samsung Galaxy not find the application class?
Any clue on how to resolve this?
I have been able to reproduce tis crash on the Samsung Galaxy emulator.
I have removed the android:name attribute declaration from the AndroidManifest.xml and it now works.