Empty map showing in my application - android

I'm doing an appplication that uses Google Maps, but the maps are not showing, and the only thing I see are blank squares.
Here is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fossa.damiano.mapsexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".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>
My activity:
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView.LayoutParams;
import com.google.android.maps.MapView;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends MapActivity {
MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
And the main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.android.maps.MapView
android:id="#+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="My Key" //I've already generated my Key
android:clickable="true" />
</RelativeLayout>
When I try to execute my application into my smartphone, the logcat shows these errors.
05-31 11:18:01.110: W/System.err(7241): IOException processing: 26
05-31 11:18:01.110: W/System.err(7241): java.io.IOException: Server returned: 3
05-31 11:18:01.115: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:18:01.115: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:18:01.120: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:18:01.120: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:18:01.120: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:18:01.125: W/System.err(7241): at java.lang.Thread.run(Thread.java:856)
05-31 11:18:16.245: W/System.err(7241): IOException processing: 26
05-31 11:18:16.245: W/System.err(7241): java.io.IOException: Server returned: 3
05-31 11:18:16.250: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:18:16.250: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:18:16.250: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:18:16.255: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:18:16.255: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:18:16.255: W/System.err(7241): at java.lang.Thread.run(Thread.java:856)
05-31 11:18:22.070: W/IInputConnectionWrapper(7241): getSelectedText on inactive InputConnection
05-31 11:18:22.070: W/IInputConnectionWrapper(7241): setComposingText on inactive InputConnection
05-31 11:18:22.070: W/IInputConnectionWrapper(7241): getExtractedText on inactive InputConnection
05-31 11:18:27.770: W/IInputConnectionWrapper(7241): showStatusIcon on inactive InputConnection
05-31 11:18:35.120: W/System.err(7241): IOException processing: 26
05-31 11:18:35.130: W/System.err(7241): java.io.IOException: Server returned: 3
05-31 11:18:35.130: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:18:35.130: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:18:35.130: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:18:35.135: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:18:35.135: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:18:35.135: W/System.err(7241): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:28.525: D/dalvikvm(8105): GC_CONCURRENT freed 169K, 14% free 9624K/11143K, paused 13ms+1ms, total 37ms
05-31 11:24:28.535: W/CursorWrapperInner(8105): Cursor finalized without prior close()
05-31 11:24:29.045: D/libEGL(8105): loaded /system/lib/egl/libEGL_mali.so
05-31 11:24:29.080: D/libEGL(8105): loaded /system/lib/egl/libGLESv1_CM_mali.so
05-31 11:24:29.085: D/libEGL(8105): loaded /system/lib/egl/libGLESv2_mali.so
05-31 11:24:29.090: D/(8105): Device driver API match
05-31 11:24:29.090: D/(8105): Device driver API version: 10
05-31 11:24:29.090: D/(8105): User space API version: 10
05-31 11:24:29.090: D/(8105): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
05-31 11:24:29.180: D/OpenGLRenderer(8105): Enabling debug mode 0
05-31 11:24:29.185: I/MapActivity(8105): Handling network change notification:CONNECTED
05-31 11:24:29.185: E/MapActivity(8105): Couldn't get connection factory client
05-31 11:24:29.295: D/dalvikvm(8105): GC_CONCURRENT freed 116K, 14% free 9954K/11463K, paused 8ms+20ms, total 53ms
05-31 11:24:29.525: W/System.err(8105): IOException processing: 26
05-31 11:24:29.525: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:29.665: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:29.665: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:30.075: W/System.err(8105): IOException processing: 26
05-31 11:24:30.075: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:30.075: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:30.075: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:30.080: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:30.080: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:30.080: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:30.080: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:30.535: W/System.err(8105): IOException processing: 26
05-31 11:24:30.535: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:30.540: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:30.810: W/System.err(8105): IOException processing: 26
05-31 11:24:30.815: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:30.815: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:30.815: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:30.815: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:30.825: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:30.825: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:30.825: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:31.100: W/System.err(8105): IOException processing: 26
05-31 11:24:31.100: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:31.105: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
I have already enabled the internet connection, so I can't find out where the probleme is.
UPDATE
I have updated the version of the Google Maps from 1 to 2.
Here are the changes:
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pocket_city"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.pocket_city.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.pocket_city.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.pocket_city.Home"
android:configChanges="keyboardHidden"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MonumentMapActivity"
android:label="#string/title_activity_monument_map"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
The activity:
package com.example.pocket_city;
import android.app.Activity;
import android.os.Bundle;
public class MonumentMapActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.monument_map);
}
}
And the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
When I try execute the code it gives me these errors:
06-01 10:12:10.496: E/AndroidRuntime(28178): FATAL EXCEPTION: main
06-01 10:12:10.496: E/AndroidRuntime(28178): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pocket_city/com.example.pocket_city.MonumentMapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.os.Looper.loop(Looper.java:137)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.main(ActivityThread.java:4921)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.reflect.Method.invoke(Method.java:511)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
06-01 10:12:10.496: E/AndroidRuntime(28178): at dalvik.system.NativeStart.main(Native Method)
06-01 10:12:10.496: E/AndroidRuntime(28178): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Activity.setContentView(Activity.java:1924)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.example.pocket_city.MonumentMapActivity.onCreate(MonumentMapActivity.java:11)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Activity.performCreate(Activity.java:5206)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
06-01 10:12:10.496: E/AndroidRuntime(28178): ... 11 more
06-01 10:12:10.496: E/AndroidRuntime(28178): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Fragment.instantiate(Fragment.java:584)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Fragment.instantiate(Fragment.java:552)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Activity.onCreateView(Activity.java:4849)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
06-01 10:12:10.496: E/AndroidRuntime(28178): ... 21 more
06-01 10:12:10.496: E/AndroidRuntime(28178): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
06-01 10:12:10.496: E/AndroidRuntime(28178): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Fragment.instantiate(Fragment.java:574)
06-01 10:12:10.496: E/AndroidRuntime(28178): ... 24 more
UPDATE 2
I made another application that shows only the maps and it works!!
But when I tried to add that code to my application, it gives the same errors displayed above!
So, why don't the maps work on both application?

The easiest way to migrate from deprecated API v1 to API v2 is to
remove all your code related to maps
follow this link: https://developers.google.com/maps/documentation/android/start

The docs state:
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment
about the use of MapFragment class:
Use this class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment.
you min SDK is 11 therefore you should use SupportMapFragment or change you min SDK level.

Related

selectableItemBackground crashing App

i'm trying to make ImageButton using
android:background="?attr/selectableItemBackground" but my app crashed. I just following this answer and this question. Any idea?
Thanks for your help.
activity.xml
<ImageButton
android:id="#+id/signUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/signIn"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"
android:background="?attr/selectableItemBackground"
android:src="#drawable/sign_up"
android:contentDescription="#string/button_sign_up"
/>
Log Cat
05-31 18:50:24.077: W/dalvikvm(28619): threadid=1: thread exiting with uncaught exception (group=0x41d0b2a0)
05-31 18:50:24.082: E/AndroidRuntime(28619): FATAL EXCEPTION: main
05-31 18:50:24.082: E/AndroidRuntime(28619): java.lang.RuntimeException: Unable to start activity ComponentInfo{yai.properti.tujuh.tujuh.tujuh/yai.properti.tujuh.tujuh.tujuh.WelcomeActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageButton
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.os.Looper.loop(Looper.java:137)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.main(ActivityThread.java:4921)
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
05-31 18:50:24.082: E/AndroidRuntime(28619): at dalvik.system.NativeStart.main(Native Method)
05-31 18:50:24.082: E/AndroidRuntime(28619): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageButton
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.Activity.setContentView(Activity.java:1924)
05-31 18:50:24.082: E/AndroidRuntime(28619): at yai.properti.tujuh.tujuh.tujuh.WelcomeActivity.onCreate(WelcomeActivity.java:19)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.Activity.performCreate(Activity.java:5188)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
05-31 18:50:24.082: E/AndroidRuntime(28619): ... 11 more
05-31 18:50:24.082: E/AndroidRuntime(28619): Caused by: java.lang.reflect.InvocationTargetException
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Constructor.constructNative(Native Method)
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-31 18:50:24.082: E/AndroidRuntime(28619): ... 24 more
05-31 18:50:24.082: E/AndroidRuntime(28619): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010015 a=-1}
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.content.res.Resources.loadDrawable(Resources.java:1925)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.View.<init>(View.java:3449)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.widget.ImageView.<init>(ImageView.java:114)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.widget.ImageButton.<init>(ImageButton.java:87)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.widget.ImageButton.<init>(ImageButton.java:83)
05-31 18:50:24.082: E/AndroidRuntime(28619): ... 27 more
#Gopal Gopi is correct. If you have the appcompat v7 imported properly into your project, use this for android:background in your xml:
android:background="?android:attr/selectableItemBackground"
Also, make sure that whatever item you use this on has android:clickable="true"
Good luck!
To make it work you should use AppCompact base theme in your App or Activity. Like following:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

Android run time error stating that unable find in manifesto file but I it was added

Hi I am trying to run an android app. Where my goal was to display a radar graph based on user preferences for that I have used the webview and sending the username to php file.
But Now I was getting an error stating that "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newairways/com.example.newairways.communication}: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity"
I Have tried my level best to solve this but I could able to it. and in error it was stated the communication class was not mentioned So I have also mentioned but I required the radar part to display. So Please help me in solving this.
Here is my logcat
08-04 19:59:21.861: D/gralloc_goldfish(654): Emulator without GPU emulation detected.
08-04 19:59:22.071: W/TextLayoutCache(654): computeValuesWithHarfbuzz -- need to force to single run
08-04 19:59:32.541: D/dalvikvm(654): GC_CONCURRENT freed 177K, 3% free 14296K/14599K, paused 7ms+7ms
08-04 19:59:36.962: W/TextLayoutCache(654): computeValuesWithHarfbuzz -- need to force to single run
08-04 19:59:45.762: W/SingleClientConnManager(654): Invalid use of SingleClientConnManager: connection still allocated.
08-04 19:59:45.762: W/SingleClientConnManager(654): Make sure to release the connection before allocating another one.
08-04 19:59:45.811: I/System.out(654): Response : User Found
08-04 19:59:45.811: I/System.out(654): ---IF---
08-04 19:59:46.682: D/dalvikvm(654): GC_CONCURRENT freed 214K, 3% free 14607K/14919K, paused 6ms+8ms
08-04 19:59:46.831: D/dalvikvm(654): GC_FOR_ALLOC freed 13K, 2% free 14946K/15239K, paused 52ms
08-04 19:59:50.781: D/AndroidRuntime(654): Shutting down VM
08-04 19:59:50.781: W/dalvikvm(654): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-04 19:59:50.831: E/AndroidRuntime(654): FATAL EXCEPTION: main
08-04 19:59:50.831: E/AndroidRuntime(654): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newairways/com.example.newairways.communication}: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.os.Looper.loop(Looper.java:137)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-04 19:59:50.831: E/AndroidRuntime(654): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 19:59:50.831: E/AndroidRuntime(654): at java.lang.reflect.Method.invoke(Method.java:511)
08-04 19:59:50.831: E/AndroidRuntime(654): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-04 19:59:50.831: E/AndroidRuntime(654): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-04 19:59:50.831: E/AndroidRuntime(654): at dalvik.system.NativeStart.main(Native Method)
08-04 19:59:50.831: E/AndroidRuntime(654): Caused by: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-04 19:59:50.831: E/AndroidRuntime(654): ... 11 more
08-04 20:06:29.651: D/gralloc_goldfish(707): Emulator without GPU emulation detected.
08-04 20:06:29.802: W/TextLayoutCache(707): computeValuesWithHarfbuzz -- need to force to single run
08-04 20:06:35.271: D/dalvikvm(707): GC_CONCURRENT freed 133K, 2% free 14335K/14599K, paused 7ms+6ms
08-04 20:06:47.093: W/TextLayoutCache(707): computeValuesWithHarfbuzz -- need to force to single run
08-04 20:06:55.241: W/SingleClientConnManager(707): Invalid use of SingleClientConnManager: connection still allocated.
08-04 20:06:55.241: W/SingleClientConnManager(707): Make sure to release the connection before allocating another one.
08-04 20:06:55.352: D/dalvikvm(707): GC_CONCURRENT freed 298K, 3% free 14484K/14855K, paused 6ms+8ms
08-04 20:06:55.441: I/System.out(707): Response : User Found
08-04 20:06:55.512: I/System.out(707): ---IF---
08-04 20:06:56.211: D/dalvikvm(707): GC_FOR_ALLOC freed 70K, 3% free 14754K/15111K, paused 46ms
08-04 20:06:56.334: D/dalvikvm(707): GC_FOR_ALLOC freed 3K, 3% free 15023K/15367K, paused 50ms
08-04 20:07:00.851: D/AndroidRuntime(707): Shutting down VM
08-04 20:07:00.851: W/dalvikvm(707): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-04 20:07:00.901: E/AndroidRuntime(707): FATAL EXCEPTION: main
08-04 20:07:00.901: E/AndroidRuntime(707): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newairways/com.example.newairways.communication}: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:137)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-04 20:07:00.901: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 20:07:00.901: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:511)
08-04 20:07:00.901: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-04 20:07:00.901: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-04 20:07:00.901: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
08-04 20:07:00.901: E/AndroidRuntime(707): Caused by: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-04 20:07:00.901: E/AndroidRuntime(707): ... 11 more
Here is my manifesto file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newairways"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.newairways.login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.newairways.menu"
android:label="#string/app_name" >
</activity>s
<activity
android:name="com.example.newairways.bar"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.radar"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.measure"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.plan"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.day0"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.goaltest"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.relationship"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.start"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.discipline"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.skills"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.knowledge"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.emotions"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.adaptation"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.leadership"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.lifequality"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.Globalvars"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.communication"
android:label="#string/app_name" >
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Does your activity extend android.app.activity ? Is the activity mentioned in the manifest file. Is the base package and fully qualified name of the activity class correct??

While running COCOS2D for Android FATAL EXCEPTION: main

I am newbie in COCOS2D for Android, While trying to run the sample project(HelloWorld) provided from cocos2d I got " FATAL EXCEPTION: main" and in detail that arrived in LogCat
05-31 19:11:46.920: E/AndroidRuntime(7719): FATAL EXCEPTION: main
05-31 19:11:46.920: E/AndroidRuntime(7719): java.lang.ExceptionInInitializerError
05-31 19:11:46.920: E/AndroidRuntime(7719): at java.lang.Class.newInstanceImpl(Native Method)
05-31 19:11:46.920: E/AndroidRuntime(7719): at java.lang.Class.newInstance(Class.java:1429)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.os.Looper.loop(Looper.java:123)
05-31 19:11:46.920: E/AndroidRuntime(7719): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-31 19:11:46.920: E/AndroidRuntime(7719): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 19:11:46.920: E/AndroidRuntime(7719): at java.lang.reflect.Method.invoke(Method.java:521)
05-31 19:11:46.920: E/AndroidRuntime(7719): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-31 19:11:46.920: E/AndroidRuntime(7719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-31 19:11:46.920: E/AndroidRuntime(7719): at dalvik.system.NativeStart.main(Native Method)
05-31 19:11:46.920: E/AndroidRuntime(7719): Caused by: java.lang.UnsatisfiedLinkError: Library helloworld not found
05-31 19:11:46.920: E/AndroidRuntime(7719): at java.lang.Runtime.loadLibrary(Runtime.java:461)
05-31 19:11:46.920: E/AndroidRuntime(7719): at java.lang.System.loadLibrary(System.java:557)
05-31 19:11:46.920: E/AndroidRuntime(7719): at org.cocos2dx.application.ApplicationDemo.<clinit>(ApplicationDemo.java:81)
05-31 19:11:46.920: E/AndroidRuntime(7719): ... 15 more
So can anyone please help with some idea/solution.
Again i followed reference from "http://www.multigesture.net/articles/how-to-setup-cocos2d-x-windows-and-android/"
Thanks a lot.
I recomend you to change libraries to cocos2d-x, because cocos2d for android won't be updated anymore.
Cocos2d-x works in C++, and uses JNI (Java native interface) to work. Here is all the info you will need to start using it.

iSpeech SDK Android VerifyError

I used iSpeech Demo to set up a test application with iSpeech SDK but it is giving me the following exception on which I am lost...
05-31 13:41:23.218: I/dalvikvm(271): Could not find method org.ispeech.SpeechSynthesis.getInstance, referenced from method org.ispeech.sdksample.TTSActivity.prepareTTSEngine
05-31 13:41:23.218: W/dalvikvm(271): VFY: unable to resolve static method 31: Lorg/ispeech/SpeechSynthesis;.getInstance (Landroid/app/Activity;)Lorg/ispeech/SpeechSynthesis;
05-31 13:41:23.218: D/dalvikvm(271): VFY: replacing opcode 0x71 at 0x0000
05-31 13:41:23.228: W/dalvikvm(271): VFY: unable to resolve exception class 37 (Lorg/ispeech/error/InvalidApiKeyException;)
05-31 13:41:23.228: W/dalvikvm(271): VFY: unable to find exception handler at addr 0x11
05-31 13:41:23.228: W/dalvikvm(271): VFY: rejected Lorg/ispeech/sdksample/TTSActivity;.prepareTTSEngine ()V
05-31 13:41:23.228: W/dalvikvm(271): VFY: rejecting opcode 0x0d at 0x0011
05-31 13:41:23.228: W/dalvikvm(271): VFY: rejected Lorg/ispeech/sdksample/TTSActivity;.prepareTTSEngine ()V
05-31 13:41:23.228: W/dalvikvm(271): Verifier rejected class Lorg/ispeech/sdksample/TTSActivity;
05-31 13:41:23.228: W/dalvikvm(271): Class init failed in newInstance call (Lorg/ispeech/sdksample/TTSActivity;)
05-31 13:41:23.228: D/AndroidRuntime(271): Shutting down VM
05-31 13:41:23.228: W/dalvikvm(271): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-31 13:41:23.248: E/AndroidRuntime(271): FATAL EXCEPTION: main
05-31 13:41:23.248: E/AndroidRuntime(271): java.lang.VerifyError: org.ispeech.sdksample.TTSActivity
05-31 13:41:23.248: E/AndroidRuntime(271): at java.lang.Class.newInstanceImpl(Native Method)
05-31 13:41:23.248: E/AndroidRuntime(271): at java.lang.Class.newInstance(Class.java:1429)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.os.Looper.loop(Looper.java:123)
05-31 13:41:23.248: E/AndroidRuntime(271): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-31 13:41:23.248: E/AndroidRuntime(271): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 13:41:23.248: E/AndroidRuntime(271): at java.lang.reflect.Method.invoke(Method.java:521)
05-31 13:41:23.248: E/AndroidRuntime(271): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-31 13:41:23.248: E/AndroidRuntime(271): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-31 13:41:23.248: E/AndroidRuntime(271): at dalvik.system.NativeStart.main(Native Method)
can someone help me solve this?
This thread on their forums seems to answer your question:
http://www.ispeech.org/forums/showthread.php/942-Verify-Error

Problems with iText trying to create a PDF file

I'm trying to create a PDF file when I press a button. I'm using iText library.
My activity:
package com.pdf;
import java.io.FileOutputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class PDFActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void GenerarPDF(View view)throws Exception{
Document document=new Document();
PdfWriter.getInstance(document,new FileOutputStream("generando.pdf"));
document.open();
document.add(new Paragraph("Testing testing and testing"));
document.close();
}
}
My xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#555">
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:onClick="GenerarPDF"
android:text="Button" />
</RelativeLayout>
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.READ_FRAME_BUFFER"/>
<uses-permission android:name="android.permission.BIND_INPUT_METHOD"/>
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".PDFActivity"
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>
And the log cat:
05-31 12:08:58.778: E/AndroidRuntime(662): FATAL EXCEPTION: main
05-31 12:08:58.778: E/AndroidRuntime(662): java.lang.IllegalStateException: Could not execute method of the activity
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View$1.onClick(View.java:3044)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View.performClick(View.java:3511)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View$PerformClick.run(View.java:14105)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.os.Handler.handleCallback(Handler.java:605)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.os.Handler.dispatchMessage(Handler.java:92)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.os.Looper.loop(Looper.java:137)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 12:08:58.778: E/AndroidRuntime(662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-31 12:08:58.778: E/AndroidRuntime(662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-31 12:08:58.778: E/AndroidRuntime(662): at dalvik.system.NativeStart.main(Native Method)
05-31 12:08:58.778: E/AndroidRuntime(662): Caused by: java.lang.reflect.InvocationTargetException
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View$1.onClick(View.java:3039)
05-31 12:08:58.778: E/AndroidRuntime(662): ... 11 more
05-31 12:08:58.778: E/AndroidRuntime(662): Caused by: java.lang.NoClassDefFoundError: com.itextpdf.text.Document
05-31 12:08:58.778: E/AndroidRuntime(662): at com.pdf.PDFActivity.GenerarPDF(PDFActivity.java:22)
05-31 12:08:58.778: E/AndroidRuntime(662): ... 14 more
Added logcat error:
05-31 15:26:00.411: E/dalvikvm(792): Could not find class 'com.itextpdf.text.Document', referenced from method com.pdf.PDFActivity.GenerarPDF
I think thats the real problem, but don't know the solution.
Where exactly are you trying to create the pdf file? I used the itextpdf-5.2.1.jar and was able to successfully create the pdf in the sd card. I added the following lines of codes to your program:
public void GenerarPDF(View view)throws Exception{
Document document=new Document();
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, "generando.pdf");
PdfWriter.getInstance(document,new FileOutputStream(gpxfile));
document.open();
document.add(new Paragraph("Testing testing and testing"));
document.close();
}
Hope this answer helps.
EDIT:
The error you mentioned in your comment (06-01 23:32:37.178: E/AndroidRuntime(535): Caused by: java.io.FileNotFoundException: /generando.pdf: open failed: EROFS (Read-only file system)
) is exactly what I get when I run the code you provided. The reason being that you are not specifying the location where the new file can be created/stored. Use the GenerarPDF(View view) in have pasted over here and the program will create the new pdf.
Another cause for this error might be that you don't have an sd card in your device.
change file root to this line
File root = new File(android.os.Environment.getExternalStorageDirectory(), "Notes");
looks like you forgot to call generatePDF() from onCreate()...
hope it helps!

Categories

Resources