I am working on creating my own Android JAR file, this JAR will contain Activities which I need to call however I keep getting a NoClassDefFound error. It is only an issue with Activities contained in the JAR, any other objects called from the external JAR work fine.
Below are the steps I have taken when creating this JAR
I created a new library project called LibraryTest, and placed one Activity in it called LibraryActivity, which has a basic layout called librarymain.xml with some random text.
I have marked this project as a library, retrieved the JAR from the bin folder, I then created new project called TestAddLibrary. I added the JAR file to the lib folder, I then added the librarymain.xml from the LibraryTest project to the layout folder of the TestAddLibrary project.
I then added the the LibraryActivity to the manifest of the new project. Manifest looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testaddlibrary"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testaddlibrary.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>
<activity
android:name="com.example.librarytest.LibraryActivity"
>
</activity>
</application>
</manifest>
Then in the main activity of the new project, I have this
package com.example.testaddlibrary;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.example.librarytest.LibraryActivity;
public class MainActivity extends Activity
{
Button but;
Context context;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
but = (Button) findViewById(R.id.butNext);
but.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, LibraryActivity.class);
startActivity(i);
}
});
}
}
When I click the button to launch the LibraryActivity which is stored in the JAR file, I get this error
07-10 09:20:24.798: E/AndroidRuntime(28195): FATAL EXCEPTION: main
07-10 09:20:24.798: E/AndroidRuntime(28195): java.lang.NoClassDefFoundError: com.example.librarytest.R$layout 07-10
09:20:24.798: E/AndroidRuntime(28195): at com.example.librarytest.LibraryActivity.onCreate(LibraryActivity.java:20)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.Activity.performCreate(Activity.java:5104) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.access$600(ActivityThread.java:141) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.os.Handler.dispatchMessage(Handler.java:99) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.os.Looper.loop(Looper.java:137) 07-10 09:20:24.798:
E/AndroidRuntime(28195): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-10
09:20:24.798: E/AndroidRuntime(28195): at java.lang.reflect.Method.invokeNative(Native Method) 07-10
09:20:24.798: E/AndroidRuntime(28195): at java.lang.reflect.Method.invoke(Method.java:511) 07-10 09:20:24.798:
E/AndroidRuntime(28195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 09:20:24.798: E/AndroidRuntime(28195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-10
09:20:24.798: E/AndroidRuntime(28195): at dalvik.system.NativeStart.main(Native Method)
I have read several questions on StackOverflow regarding this issue but nothing I have read has helped. I have the latest version of ADT Eclipse plugin, I have made sure that under Order and Export, I have ticked Android dependencies and Private Libraries.
Anyone have any idea what is causing this issue? Any help would be much appreciated!!
Edit: Forgot to mention other reason I am doing this is that I require my code to be hidden so I can share this out to other people without them seeing my code
You cannot package resources into jar files.
You can package pure java files that do not refer to any resources as jars.
In your case you need to reference the library project in your android project.
Library Projects
These projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time.
http://developer.android.com/tools/projects/index.html
To the question in the comment the closest resource could find
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.
How to create jar for Android Library Project
Related
This question already has answers here:
Libraries do not get added to APK anymore after upgrade to ADT 22
(7 answers)
Closed 9 years ago.
I'm trying to use fragments to create a simple, persistent navigation bar. The problem is I'm getting the following Error output.
05-23 14:58:02.861: E/AndroidRuntime(882): FATAL EXCEPTION: main
05-23 14:58:02.861: E/AndroidRuntime(882): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {org.childrensmuseum.visittcmindy/org.childrensmuseum.visittcmindy.MainActivity}: java.lang.ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.os.Looper.loop(Looper.java:137)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.ActivityThread.main(ActivityThread.java:4340)
05-23 14:58:02.861: E/AndroidRuntime(882): at java.lang.reflect.Method.invokeNative(Native Method)
05-23 14:58:02.861: E/AndroidRuntime(882): at java.lang.reflect.Method.invoke(Method.java:511)
05-23 14:58:02.861: E/AndroidRuntime(882): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-23 14:58:02.861: E/AndroidRuntime(882): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-23 14:58:02.861: E/AndroidRuntime(882): at dalvik.system.NativeStart.main(Native Method)
05-23 14:58:02.861: E/AndroidRuntime(882): Caused by: java.lang.ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity
05-23 14:58:02.861: E/AndroidRuntime(882): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-23 14:58:02.861: E/AndroidRuntime(882): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-23 14:58:02.861: E/AndroidRuntime(882): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-23 14:58:02.861: E/AndroidRuntime(882): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
05-23 14:58:02.861: E/AndroidRuntime(882): ... 11 more
My main activity looks like this:
package org.childrensmuseum.visittcmindy;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.ImageButton;
public class MainActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFormat(PixelFormat.RGBA_8888);
findViewById(R.id.NavigationBar).getBackground().setDither(true);
ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
homeButton.setColorFilter(Color.argb(255, 90, 179, 0));
}
#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;
}
}
My Fragment looks like this:
package org.childrensmuseum.visittcmindy;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainNavigation extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.navigation_main, container, false);
}
}
Lastly my main activity xml file looks like this:
<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" >
<ImageView
android:id="#+id/HomeBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/homescreen_desc"
android:src="#drawable/homescreen"
android:scaleType="centerCrop"
/>
<fragment android:name="org.childrensmuseum.visittcmindy.MainNavigation"
android:id="#+id/NavigationBar"
android:layout_gravity="bottom" />
</RelativeLayout>
What am I missing?
EDITED to try to make it a general answer to this issue (in this case, the correct answer is provided by #Raghunandan):
Humm... so your MainActivity is "lost" (ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity):
1.- May be an Eclipse (or whatever IDE you are using) building issue. Clean your Project and rebuild it and/or restart Eclipse.
2.- It can be a problem with your Manifest file. Add your Activity in your 'AndroidManifest.xml', making sure your Package and Activity names are correctly written (check caps). An example could be:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.childrensmuseum.visittcmindy">
<application>
<activity android:name=".MainActivity"></activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
3.- Doesn't seem to be your case, but sometimes external libraries are not correctly included in the Build Path. You have to put your third party libraries in a "libs" folder and re-reference them (Right-click, properties, Java Build Path, Libraries, Add Jar...).
Shared libraries like the Maps library, which is not a part of the standard Android library, must be declared in the Android Manifest. Open the AndroidManifest.xml file and add the following as a child of the element:
<uses-library android:name="com.google.android.maps"/>
4.- #Raghunandan gives a solution here in case you've updated to Android SDK Tools Rev 22.
Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.
I want to load the google map API on my android. I try everything I search but it still crash.
this is my MainActivity.java
package com.example.androidmapsv2;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
This is my layout activity_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" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidmapsv2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission>
<uses-permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Require OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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="com.example.androidmapsv2.MainActivity"
android:label="aaa" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDr9xN8L3sF6W2ZRWmTR7q0lhTeOWhXEfQ" />
</application>
</manifest>
This is the key i've got
This is the libs included (Solved in update)
and i don't have a real android device, so i install it on emulator in this tutorial
This is the logcat
01-09 18:05:19.184: E/Trace(1366): error opening trace file: No such file or directory (2)
01-09 18:05:19.354: W/dalvikvm(1366): Unable to resolve superclass of Lcom/example/androidmapsv2/MainActivity; (5)
01-09 18:05:19.354: W/dalvikvm(1366): Link of class 'Lcom/example/androidmapsv2/MainActivity;' failed
01-09 18:05:19.365: D/AndroidRuntime(1366): Shutting down VM
01-09 18:05:19.365: W/dalvikvm(1366): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-09 18:05:19.384: E/AndroidRuntime(1366): FATAL EXCEPTION: main
01-09 18:05:19.384: E/AndroidRuntime(1366): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.androidmapsv2/com.example.androidmapsv2.MainActivity}: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.os.Looper.loop(Looper.java:137)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:05:19.384: E/AndroidRuntime(1366): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 18:05:19.384: E/AndroidRuntime(1366): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.NativeStart.main(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): Caused by: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
01-09 18:05:19.384: E/AndroidRuntime(1366): ... 11 more
UPDATED
i've tried to copy the google-play-services_lib to workspace and red mark disappear
but it come another error. It missing the google-play-services_lib.jar (the lib folder name + .jar). how to fix it
when i click the google-play-services_lib.jar, the remove button doesn't show up(like picture). However i try remove all Android Dependencies and import the others lib again. now it working, but still crash.
I've tried change
MainActivity extends Activity
To
MainActivity extends FragmentActivity
and the layout
<?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" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
it appear another error. help me, now i'm out of solution for this
Finally, i solved my error. It caused by my eclipse (i guess). When you add the library class, it automatically appear "google-play-services_lib.jar", you don't have to do anything. I reinstall Eclipse and everything work fine
I also faces this kind of the problem,when first time coding for the map with API V2.
Just try using the extends with FragmentActivity instead of the Activity
you have to copy the project(goolge_play_services) into your workspace and then attach it to your project. In above image it show the cross red,so select it and remove and then after once again add attach the library with the project.
It is required to use SupportMapFragment if API version is below 11
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Important
Don't forget to extend your Activity with FragmentActivity
you have to copy the project(goolge_play_services) into your workspace and then attach it to your project.
What you are doing is importing the project and not checkmarking the copy the project into workspace due to which it showing you wrong mark in added libraries.
So just checkmark the the copy the project into workspace while importing the google_play_services project and then attach it to your project.
As here i can see that you are using the api level 8 and AFAIK the "Fragments" are supported from the 11.
So here you need to use the compatible library of the fragments.
And also make sure that you have also imported the library of the google-play-service in your workspace and added it in your application.
You need to edit your application's AndroidManifest.xml file, and add the following declaration within the element. This embeds the version of Google Play services that the app was compiled with.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I’m currently using JSoup as external jar and the following snippet throws runtime exception in emulator and eventually app crashes:
Document doc = Jsoup.connect(“http://www.cnn.com”).get();
06-18 14:00:17.272: I/dalvikvm(424): Could not find method org.jsoup.Jsoup.connect, referenced from method com.pamir.ODeskActivity.getList
06-18 14:00:17.272: W/dalvikvm(424): VFY: unable to resolve static method 25: Lorg/jsoup/Jsoup;.connect (Ljava/lang/String;)Lorg/jsoup/Connection;
06-18 14:00:17.282: D/dalvikvm(424): VFY: replacing opcode 0×71 at 0×0007
06-18 14:00:17.892: D/AndroidRuntime(424): Shutting down VM
06-18 14:00:17.905: W/dalvikvm(424): threadid=1: thread exiting with uncaught exception (group=0×40014760)
06-18 14:00:17.912: E/AndroidRuntime(424): FATAL EXCEPTION: main
06-18 14:00:17.912: E/AndroidRuntime(424): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
06-18 14:00:17.912: E/AndroidRuntime(424): at com.pamir.ODeskActivity.getList(ODeskActivity.java:24)
Here is the manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ODeskActivity"
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>
What am I doing wrong? Any help is appreciated.
Make certain your JSoup jar file is exported along with the rest of your code.
Right click Project
Java Build Path
Order and Export
Check the box next your Jsoup jar entry.
Then reload the app onto your emulator or device.
To extend what forgivengod said.
Also.
Right click Project
Click Android Tools
Click Fix Project Properties
And.
Click Project
Clean
I seem to have a tricky problem since the latest ADT update to release 17.
I have made a simple application to illustrate my problem, I don't know if I'm doing anything wrong. The main Activity of my application is inheriting from FragmentActivity in the support package and somehow the application crashes at launch.
To illustrate, I made a sample project.
First of all, here is the code of my dummy class, DummyProjectActivity, very simple:
public class DummyProjectActivity extends FragmentActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Then, there is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="be.emich.labs"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".DummyProjectActivity"
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 .jar file is imported correctly in the project and I am getting this stack trace:
E/AndroidRuntime(11509): FATAL EXCEPTION: main
E/AndroidRuntime(11509): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{be.emich.labs/be.emich.labs.DummyProjectActivity}: java.lang.ClassNotFoundException: be.emich.labs.DummyProjectActivity
E/AndroidRuntime(11509): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
E/AndroidRuntime(11509): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(11509): at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(11509): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(11509): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(11509): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(11509): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(11509): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(11509): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(11509): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(11509): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(11509): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(11509): Caused by: java.lang.ClassNotFoundException: be.emich.labs.DummyProjectActivity
E/AndroidRuntime(11509): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime(11509): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(11509): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(11509): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
E/AndroidRuntime(11509): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
E/AndroidRuntime(11509): ... 11 more
What am I doing wrong here? Could this be a bug in the latest dev tools?
I am encountering the problem in every project that uses FragmentActivity from the compatibility library. I don't get what could be wrong. Anyone else having this problem? Help would be greatly appreciated. I'm not having the problem with an Activity that inherits from FragmentActivity. I have uninstalled/reinstalled the application. Done various "clean project". Restarted Eclipse.
UPDATE: The issue is apparently not linked to the compatibility package but the way ADT r17 handles linking of jar files. Jars to be included should be put into the libs/ folder and ADT will link them automatically. Otherwise they will be missing from the APK and make the app crash whenever the code from the jarfile is invoked.
Until the latest release tools right click > Add compatibility package on my project wasn't working and I included the jar file manually through the project properties. I tried "Add compatibility package" again and since r17 it seems this is fixed for my machine. This fixed the problem.
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
I had a lot of trouble too. Just beginning developing and this kind of thing occured hahaha
I've got the following Button declared in my main.xml
<Button android:name="#+id/clickedStartService"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="clickedStartService"
android:text="Start"
/>
<Button android:name="#+id/clickedStopService"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="clickedStopService"
android:text="Stop"
/>
And I have the following methods in the activity..
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void clickedStartService(View v)
{
startService(new Intent(this, LocalService.class));
}
public void clickedStopService(View v)
{
stopService(new Intent(this, LocalService.class));
}
I'm getting the following error when I click the button. I have tried rebuilding the project in my IDE and have also restarted the emulator, but same error re-appears. I've followed the documentation on the Android developers site, and I've had this working in a separate project, I just can't get it to work here..
ERROR/AndroidRuntime(335): FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not find a method clickedStartService(View) in the activity class com.jameselsey.observerpattern.MyApp for onClick handler on view class android.widget.Button
at android.view.View$1.onClick(View.java:2059)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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.NoSuchMethodException
at java.lang.Class.getDeclaredMethods(Native Method)
at java.lang.ClassCache.getDeclaredPublicMethods(ClassCache.java:166)
at java.lang.ClassCache.getDeclaredMethods(ClassCache.java:179)
at java.lang.ClassCache.findAllMethods(ClassCache.java:249)
at java.lang.ClassCache.getFullListOfMethods(ClassCache.java:223)
at java.lang.ClassCache.getAllPublicMethods(ClassCache.java:204)
at java.lang.Class.getMethod(Class.java:984)
at android.view.View$1.onClick(View.java:2052)
... 11 more
XML click listeners were added in Android 1.6. Check your AndroidManifest to verify that your min SDK version isn't set to cupcake (1.5, or API level 3) -
If you're using Eclipse with the ADT plugin, also check project properties > Android and check the build target, make sure it's Donut or higher.
You need to do:
import android.view.View
instead of:
import view.View