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!
Related
I am working on an application that reads in data from an RSS feed. I did not develop the application, I am trying to fix a bug causing it to stop working. When I attempt to run it on my computer using an emulator my logcat displays the following:
Can anyone shed some light on the issue? It seems to be telling me It cannot find a class called NewsRssActivity but I can clearly see it listed in the project explorer window.
05-20 10:26:51.378: E/AndroidRuntime(1027): FATAL EXCEPTION: main
05-20 10:26:51.378: E/AndroidRuntime(1027): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.newsrss.Feed/com.newsrss.Feed.NewsRssActivity}: java.lang.ClassNotFoundException: com.newsrss.Feed.NewsRssActivity
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.os.Looper.loop(Looper.java:137)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-20 10:26:51.378: E/AndroidRuntime(1027): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 10:26:51.378: E/AndroidRuntime(1027): at java.lang.reflect.Method.invoke(Method.java:511)
05-20 10:26:51.378: E/AndroidRuntime(1027): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-20 10:26:51.378: E/AndroidRuntime(1027): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-20 10:26:51.378: E/AndroidRuntime(1027): at dalvik.system.NativeStart.main(Native Method)
05-20 10:26:51.378: E/AndroidRuntime(1027): Caused by: java.lang.ClassNotFoundException: com.newsrss.Feed.NewsRssActivity
05-20 10:26:51.378: E/AndroidRuntime(1027): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-20 10:26:51.378: E/AndroidRuntime(1027): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-20 10:26:51.378: E/AndroidRuntime(1027): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-20 10:26:51.378: E/AndroidRuntime(1027): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
05-20 10:26:51.378: E/AndroidRuntime(1027): ... 11 more
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.newsrss.Feed" android:versionCode="2" android:versionName="1.1">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15"
android:maxSdkVersion="17" />
<uses-feature android:glEsVersion="0x00020000"
android:required="true" />
<permission android:name="com.newsrss.Feed.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.newsrss.Feed.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:label="#string/app_name" android:icon="#drawable/app_icon"
android:theme="#style/Theme.Sherlock.Light.NoActionBar">
<activity android:name="NewsRssActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.newsrss.Feed.DetailsArticle" />
<activity android:name="com.newsrss.Feed.DetailsPodcast" />
<activity android:name="com.newsrss.Feed.DetailsJobs" />
<activity android:name="com.newsrss.Feed" />
<activity android:name="com.newsrss.Feed.Legal" />
<activity android:name="com.newsrss.Feed.SearchActivity"
android:windowSoftInputMode="adjustPan" />
<activity android:name="com.newsrss.Feed.DetailsSearch" />
<activity android:label="#string/app_name" android:name="com.facebook.LoginActivity" />
<activity android:name="com.newsrss.Feed.MapActivity" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCHdfGghvsiLqmv6e_jUCnPfBW3FjZ7YYI" />
</application>
</manifest>
NewsRssActivity.java
package com.newsrss.Feed;
import android.app.Dialog;
import android.app.LoaderManager;
import android.app.ProgressDialog;
import android.content.*;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.facebook.Session;
import com.fortysevendeg.swipelistview.BaseSwipeListViewListener;
import com.fortysevendeg.swipelistview.SwipeListView;
import com.google.analytics.tracking.android.EasyTracker;
import com.slidingmenu.lib.SlidingMenu;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NewsRssActivity extends shaerToSocial {
Check if your Activity is defined in the Manifest:
<activity
android:name="com.newsrss.Feed.NewsRssActivity">
</activity>
I am a beginner in android developmnt.I followed a series of tutorials and made a piece of code.Whenever I run the app in the emulator it shows "Sorry! the application XXXX has stopped unexpectedly..Please try again." Please help me solve this error.
Here is the code I used...
package newapp.com;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
int counter;
Button add,sub;
TextView display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add= (Button) findViewById(R.id.badd);
sub= (Button) findViewById(R.id.bsub);
display= (TextView) findViewById(R.id.tdisplay);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
}
});
}}
This is xml code i used....
<LinearLayout 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"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="newapp.com.MainActivity$PlaceholderFragment" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="The sum is"
android:textSize="45dp"
android:gravity="center"
android:id="#+id/tdisplay"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="add"
android:id="#+id/badd"
/>
<Button
android:id="#+id/bsub"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="subtract" />
</LinearLayout>
And here is the manifest....
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="newapp.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="newapp.com.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>
This is my logcat...and how logcat is useful to resolve this issue.
05-07 13:22:31.058: I/dalvikvm(609): Could not find method
android.content.pm.PackageManager.getActivityLogo, referenced from method
android.support.v7.internal.widget.ActionBarView.<init>
05-07 13:22:31.058: W/dalvikvm(609): VFY: unable to resolve virtual method 318:
Landroid/content/pm/PackageManager;.getActivityLogo
(Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-07 13:22:31.058: D/dalvikvm(609): VFY: replacing opcode 0x6e at 0x008b
05-07 13:22:31.058: I/dalvikvm(609): Could not find method
android.content.pm.ApplicationInfo.loadLogo, referenced from method
android.support.v7.internal.widget.ActionBarView.<init>
05-07 13:22:31.068: W/dalvikvm(609): VFY: unable to resolve virtual method 314:
Landroid/content/pm/ApplicationInfo;.loadLogo
(Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-07 13:22:31.088: D/dalvikvm(609): VFY: replacing opcode 0x6e at 0x0099
05-07 13:22:31.108: D/dalvikvm(609): VFY: dead code 0x008e-0092 in
Landroid/support/v7/internal/widget/ActionBarView;.<init>
(Landroid/content/Context;Landroid/util/AttributeSet;)V
05-07 13:22:31.108: D/dalvikvm(609): VFY: dead code 0x009c-00a0 in
Landroid/support/v7/internal/widget/ActionBarView;.<init>
(Landroid/content/Context;Landroid/util/AttributeSet;)V
05-07 13:22:31.458: D/AndroidRuntime(609): Shutting down VM
05-07 13:22:31.458: W/dalvikvm(609): threadid=1: thread exiting with uncaught exception
(group=0x4001d800)
05-07 13:22:31.478: E/AndroidRuntime(609): FATAL EXCEPTION: main
05-07 13:22:31.478: E/AndroidRuntime(609): java.lang.RuntimeException: Unable to start
activity ComponentInfo{newapp.com/newapp.com.MainActivity}:
java.lang.NullPointerException
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-07 13:22:31.478: E/AndroidRuntime(609): at android.os.Looper.loop(Looper.java:123)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.main(ActivityThread.java:4627)
05-07 13:22:31.478: E/AndroidRuntime(609): at
java.lang.reflect.Method.invokeNative(Native Method)
05-07 13:22:31.478: E/AndroidRuntime(609): at
java.lang.reflect.Method.invoke(Method.java:521)
05-07 13:22:31.478: E/AndroidRuntime(609): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-07 13:22:31.478: E/AndroidRuntime(609): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-07 13:22:31.478: E/AndroidRuntime(609): at dalvik.system.NativeStart.main(Native
Method)
05-07 13:22:31.478: E/AndroidRuntime(609): Caused by: java.lang.NullPointerException
05-07 13:22:31.478: E/AndroidRuntime(609): at
newapp.com.MainActivity.onCreate(MainActivity.java:32)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-07 13:22:31.478: E/AndroidRuntime(609): ... 11 more
05-07 13:22:41.409: I/Process(609): Sending signal. PID: 609 SIG: 9
Apply theme in activity in manifest file
android:theme="#style/Theme.AppCompat.Light"
And in styles.xml
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
The layout you posted that contains the Buttons and TextView you use is not R.layout.activity_main.
Make sure R.layout.activity_main is the layout that contains R.id.badd, R.id.bsub and R.id.tdisplay
I have developed test application Using worklight for android environment. When i test that on worklight server it works fine, but when i tried to run the same on android virtual device (AVD) it throws an error message like Sorry The application Test (process com.Test) has stopped unexpectedly. Please try again. and the application terminates.
I am using Eclipse 4.2 and android version for AVD is 2.3.3
What is the solution of this...???
`
06-21 10:59:28.407: W/dalvikvm(1209): Unable to resolve superclass of Lcom/Test/Test; (14)
06-21 10:59:28.407: W/dalvikvm(1209): Link of class 'Lcom/Test/Test;' failed
06-21 10:59:28.427: D/AndroidRuntime(1209): Shutting down VM
06-21 10:59:28.427: W/dalvikvm(1209): threadid=1: thread exiting with uncaught exception (group=0xb607d4f0)
06-21 10:59:28.467: E/AndroidRuntime(1209): FATAL EXCEPTION: main
06-21 10:59:28.467: E/AndroidRuntime(1209): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.Test/com.Test.Test}: java.lang.ClassNotFoundException: com.Test.Test in loader dalvik.system.PathClassLoader[/data/app/com.Test-1.apk]
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.os.Looper.loop(Looper.java:130)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.reflect.Method.invoke(Method.java:507)
06-21 10:59:28.467: E/AndroidRuntime(1209): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-21 10:59:28.467: E/AndroidRuntime(1209): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-21 10:59:28.467: E/AndroidRuntime(1209): at dalvik.system.NativeStart.main(Native Method)
06-21 10:59:28.467: E/AndroidRuntime(1209): Caused by: java.lang.ClassNotFoundException: com.Test.Test in loader dalvik.system.PathClassLoader[/data/app/com.Test-1.apk]
06-21 10:59:28.467: E/AndroidRuntime(1209): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-21 10:59:28.467: E/AndroidRuntime(1209): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-21 10:59:28.467: E/AndroidRuntime(1209): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
06-21 10:59:28.467: E/AndroidRuntime(1209): ... 11 more
`
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Test"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="false"
android:resizeable="false"
android:anyDensity="false"
/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- Push permissions -->
<permission android:name="com.Test.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.Test.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:label="#string/app_name"
android:debuggable="true"
android:icon="#drawable/icon" >
<activity android:name=".Test"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.Test.Test.NOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Preference Activity -->
<activity
android:name="com.worklight.common.WLPreferences"
android:label="Worklight Settings">
</activity>
<!-- Push service -->
<!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver
It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->
<service android:name=".GCMIntentService" />
<!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.Test" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.Test" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="10" />
</manifest>
Test.Java
package com.Test;
import android.os.Bundle;
import com.worklight.androidgap.WLDroidGap;
public class Test extends WLDroidGap {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
/**
* onWLInitCompleted is called when the Worklight runtime framework initialization is complete
*/
#Override
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
}
}
AVD 2.3.x has a known bug which prevents it from running WebView based apps. Use OS 4.x or 2.2.
am getting this exception:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{business.premium/business.premium.Problemio}:
java.lang.ClassNotFoundException: business.premium.Problemio
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
... 11 more
java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
it says that class is not there, but it IS there. I tried to configure things in my project's build path, but not too sure what to tweak there.
And here is how I start my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="business.premium"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:name="MyApplication"
android:debuggable="true">
<activity
android:name=".Problemio"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any thoughts on how to solve this, or what to look into? Thanks!
Its because you specified the "android:name" attribute in the application node in the manifest file.
Do not use the android:name attribute!
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
This answer is taken from: java.lang.ClassNotFoundException on working app
I'm trying to use OSMdroid for a project, and i'm utterly unable to make the simplest code work.
Well, a few days ago i was able to display maps and so on, and now i can't even instantiate a MapView.
I reduced the code to its sipmlest form.
I work with eclipse. I downloaded osmdroid-android-3.0.5.jar and slf4j-android-1.5.8.jar, and i included them in the project by adding lines to the classpath file
<classpathentry kind="lib" path="lib/osmdroid-android-3.0.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-android-1.5.8.jar"/>
Or by right clicking on them then Build Path-> Add to build path (both gave the same result, anyway)
Then i typed this code:
import android.app.Activity;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.os.Bundle;
public class TestMapActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mv=new MapView(this,256);
}
}
And i get a bug when running it on the emulator:
04-17 09:10:31.181: E/AndroidRuntime(595): FATAL EXCEPTION: main
04-17 09:10:31.181: E/AndroidRuntime(595): java.lang.NoClassDefFoundError: org.osmdroid.views.MapView
04-17 09:10:31.181: E/AndroidRuntime(595): at testmap.sagem.TestMapActivity.onCreate(TestMapActivity.java:17)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.Activity.performCreate(Activity.java:4465)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.os.Looper.loop(Looper.java:137)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-17 09:10:31.181: E/AndroidRuntime(595): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 09:10:31.181: E/AndroidRuntime(595): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 09:10:31.181: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 09:10:31.181: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 09:10:31.181: E/AndroidRuntime(595): at dalvik.system.NativeStart.main(Native Method)
When i comment out the "MapView mv=new MapView(this,256);" it works, so i don't understand why the mapview can't be instantiated.
Any idea on this?
Thank you for your attention.
EDIT:
The AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="testmap.sagem"
android:versionCode="1"
android:versionName="1.0" >
<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_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TestMapActivity"
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 main.xml file:
<?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:orientation="vertical" >
</LinearLayout>
Change Folder name "lib" to "libs" and put all jar files in that folder and Charge path of jar
files to "libs" folder. I am not sure but I think it will work.
Try to use the 3.0.7 and clean the project.
Let me know.
http://code.google.com/p/osmdroid/downloads/list