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.
Related
when i am using devsmartliberary from github in my project my app is going to crash i am unable to find out this error .i am new to android plz help me
this is my main activity
package com.example.horizontal;
import com.devsmart.android.ui.HorizontalListView;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ListView;
public class MainActivity extends Activity {
String[] itemName = { "OverView", "History", "Budget", "Distribution",
"Statistics" };
Integer[] imageId = { R.drawable.image1, R.drawable.image2,
R.drawable.image3, R.drawable.ic_launcher, R.drawable.image5 };
ListView lvList;
GridView gvList;
CustomerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.horizontal);
adapter = new CustomerAdapter(this, itemName, imageId);
// gvList = (GridView) findViewById(R.id.gvList);
// gvList.setAdapter(adapter);
HorizontalListView hlv = (HorizontalListView) findViewById(R.id.listview);
//lvList = (ListView) findViewById(R.id.lvList);
hlv.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
This is my horizontal.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:orientation="vertical"
tools:context=".MainActivity" >
<com.devsmart.android.ui.HorizontialListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd" />
</LinearLayout>
Exception are getting here
03-24 15:19:36.692: E/AndroidRuntime(881): FATAL EXCEPTION: main
03-24 15:19:36.692: E/AndroidRuntime(881): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.horizontal/com.example.horizontal.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.devsmart.android.ui.HorizontialListView
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.access$600(ActivityThread.java:122)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.os.Looper.loop(Looper.java:137)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-24 15:19:36.692: E/AndroidRuntime(881): at java.lang.reflect.Method.invokeNative(Native Method)
03-24 15:19:36.692: E/AndroidRuntime(881): at java.lang.reflect.Method.invoke(Method.java:511)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-24 15:19:36.692: E/AndroidRuntime(881): at dalvik.system.NativeStart.main(Native Method)
03-24 15:19:36.692: E/AndroidRuntime(881): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.devsmart.android.ui.HorizontialListView
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.Activity.setContentView(Activity.java:1835)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.example.horizontal.MainActivity.onCreate(MainActivity.java:26)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.Activity.performCreate(Activity.java:4465)
Analysis:
com.devsmart.android.ui.HorizontialListView is the class path from
your library project which you have used in xml
If properly not refered, it cause Binary Xml Error
Your Log says:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.horizontal/com.example.horizontal.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.devsmart.android.ui.HorizontialListView
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
It means: The library project is not properly referred in your project
Solution:
Right click on your project -> Android -> in the right bottom -> click add and point to the library project of horizontal library, so that it is refered properly in your project
Edit
horizontal.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:orientation="vertical"
tools:context=".MainActivity" >
<com.devsmart.android.ui.HorizontialListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ddd" />
</LinearLayout>
I had the same issue and then i downloaded it's jar file and added that in my project..
You better use Recycler View for horizontal scrolling that is much much better than Horizontal listView and is one of the latest approaches.
Secondly if you still want to use HSV then download this https://www.dropbox.com/s/ihfmr149z6liabb/devsmartlib.jar?dl=0 library and add it in your libraries folder and then right click and click Add as library and use HSV
You are getting inflate error that means android is not able to find your HorizontalListView class, here is check list for getting out of this error:
As said by #Devrath you have to add library project to your project, check ReferencingLibraryProject.
If you still get this error then right click on project-> Properties -> select java builder path-> select Order and Export-> Make sure that "Android private libraries" must be checked.
If still your problem not solved then check and make sure you have given correct class reference in you layout file. For custom view you need to give full path to your class by including package name <packagename>.HorizontalListView.
I had this same issue I've spent many infuriating hours figuring it out. The only solution I could come up with was to change the devsmart package name then re-add it to my project then added it to the libraries. I believe this started because I changed my project package name so don't change your package name when working with this library I guess.
Ok first you need to add an 's' to the project library folder 'devsmartlibs'
NOTE: That you only have to do this if it won't let you add the project because it's already been added as a project.
Then you import it as a project so: File -> Import -> Existing android code into workspace. Then select the project location in browse and select finish.
After that right click on Your Project -> Properties -> Android -> Add (Bottom Right) -> now add the new library you've added to you project (devsmartlibs).
If this causes issues make sure that devsmartlibs has the same 'android-support-v4.jar' as your project because this can cause issues.
This worked for me I hope it helps.
I've got problem with using setText() method on Android 16 (4.1) app. I'm trying to put programatically anything into TextView tvopis (here's just some test string, later I plan on putting there string from intent).
When I open activity opis, the app crashes. If I comment setText() part, everything works fine.
Here's java code
package com.example.pierwszyandroid;
import android.app.Activity;
import android.app.ActionBar;
import android.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.TextView;
import android.os.Build;
public class OpisActivity extends Activity {
public TextView tvopis;
String txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opis);
tvopis = (TextView) findViewById(R.id.tvotest);
tvopis.setText("txt test");
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}
}
Here's fragment_opis.xml for this activity:
<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"
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="com.example.pierwszyandroid.OpisActivity$PlaceholderFragment" >
<TextView
android:id="#+id/tvotest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
</RelativeLayout>
and this is activity_opis.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.pierwszyandroid.OpisActivity"
tools:ignore="MergeRootFrame" />
and here's logcat with error message:
04-18 10:44:59.665: I/Choreographer(723): Skipped 206 frames! The application may be doing too much work on its main thread.
04-18 10:46:34.016: I/Choreographer(723): Skipped 41 frames! The application may be doing too much work on its main thread.
04-18 10:46:34.135: D/AndroidRuntime(723): Shutting down VM
04-18 10:46:34.135: W/dalvikvm(723): threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
04-18 10:46:34.155: E/AndroidRuntime(723): FATAL EXCEPTION: main
04-18 10:46:34.155: E/AndroidRuntime(723): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pierwszyandroid/com.example.pierwszyandroid.OpisActivity}: java.lang.NullPointerException
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.os.Looper.loop(Looper.java:137)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-18 10:46:34.155: E/AndroidRuntime(723): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 10:46:34.155: E/AndroidRuntime(723): at java.lang.reflect.Method.invoke(Method.java:511)
04-18 10:46:34.155: E/AndroidRuntime(723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-18 10:46:34.155: E/AndroidRuntime(723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-18 10:46:34.155: E/AndroidRuntime(723): at dalvik.system.NativeStart.main(Native Method)
04-18 10:46:34.155: E/AndroidRuntime(723): Caused by: java.lang.NullPointerException
04-18 10:46:34.155: E/AndroidRuntime(723): at com.example.pierwszyandroid.OpisActivity.onCreate(OpisActivity.java:25)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.Activity.performCreate(Activity.java:5008)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-18 10:46:34.155: E/AndroidRuntime(723): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-18 10:46:34.155: E/AndroidRuntime(723): ... 11 more
Any help would be really appreciated, because I couldn't find any answer on already posted similar problems.
If you look at the log cat, you will see that you have a null pointer exception when you try to set the text to the text view (line 25 in your OpisActivity).
This means that the txt view is not found in the layout and thus cannot be initialised. Since your textview is in the fragment, you have to first add the fragment to the layout and then find the view.
To solve your problem, move the findById and setText method after the fragment initialisation in your onCreate method, like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opis);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}
tvopis = (TextView) findViewById(R.id.tvotest);
tvopis.setText("txt test");
}
Your app crashed because your TextView tvotest belong to fragment_opis.xml layout and you have to set activity_opis.xml file to your activity.
so initialized PlaceholderFragment() first and then initialized your TextView tvotest or change your layout like
setContentView(R.layout.fragment_opis.xm)
You have wrongly set your layout in your onCreate() method. You TextView resides inside layout fragment_opis.xml whereas you have set layout as setContentView(R.layout.activity_opis);.
Just change your setContentView(R.layout.activity_opis); line
to as below
setContentView(R.layout. fragment_opis);
change this setContentView(R.layout.activity_opis);
to this
setContentView(R.layout.fragment_opis.xml);
Sometimes when creating layouts in fragments you copy and paste xml code that has duplicate IDs. When you then call the id of the pasted resources it will try to invoke the first defined resources which is probably null at runtime. Double check if the TextView's id is found only in one fragment's Xml. If not work around "findviewbyid".I hope that helps
try checking out the answer at https://stackoverflow.com/a/20177019/14229871 .I was encountering a similar problem with textView, every time I call set text my app would crash. I think it's a matter of how u call set text.
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
I want to change my project from Activity to FragmentActivity. The first step was to create the fragment:
public class Frag1 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater
.inflate(R.layout.detail_fragment, container, false);
return view;
}
}
the detail_fragment is a simple LinearLayout with a TextView
The second Step was to (after my SplashScreen) make the parent class to FragmentActivity:
public class TestFrag extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frag_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
The R.layout.frag_main:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frag"
android:name=".fragments.Frag1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
On my SplashScreen is say know:
Intent myInt = new Intent(this, TestFrag.class);
startActivity(myInt);
But alwas i get these errors:
05-18 23:09:51.543: W/dalvikvm(28644): Unable to resolve superclass of Lws/stefma/projectname/TestFrag; (20)
05-18 23:09:51.543: W/dalvikvm(28644): Link of class 'Lws/stefma/projectname/TestFrag;' failed
05-18 23:09:51.543: E/dalvikvm(28644): Could not find class 'ws.stefma.projectname.TestFrag', referenced from method ws.stefma.projectname.Activity_Login_Registration.onCreate
05-18 23:09:51.543: W/dalvikvm(28644): VFY: unable to resolve const-class 94 (Lws/stefma/projectname/TestFrag;) in Lws/stefma/projectname/Activity_Login_Registration;
05-18 23:09:51.543: D/dalvikvm(28644): VFY: replacing opcode 0x1c at 0x000b
05-18 23:09:51.583: D/AndroidRuntime(28644): Shutting down VM
05-18 23:09:51.583: W/dalvikvm(28644): threadid=1: thread exiting with uncaught exception (group=0x41850930)
05-18 23:09:51.593: E/AndroidRuntime(28644): FATAL EXCEPTION: main
05-18 23:09:51.593: E/AndroidRuntime(28644): java.lang.NoClassDefFoundError: ws.stefma.projectname.TestFrag
05-18 23:09:51.593: E/AndroidRuntime(28644): at ws.stefma.projectname.Activity_Login_Registration.onCreate(Activity_Login_Registration.java:30)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.Activity.performCreate(Activity.java:5104)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.os.Looper.loop(Looper.java:137)
05-18 23:09:51.593: E/AndroidRuntime(28644): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-18 23:09:51.593: E/AndroidRuntime(28644): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 23:09:51.593: E/AndroidRuntime(28644): at java.lang.reflect.Method.invoke(Method.java:511)
05-18 23:09:51.593: E/AndroidRuntime(28644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-18 23:09:51.593: E/AndroidRuntime(28644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-18 23:09:51.593: E/AndroidRuntime(28644): at dalvik.system.NativeStart.main(Native Method)
I have no idea why...
The confused about that:
If I go back from FragmentActivity to Activity all runs fine without errors!!!
Also i have these in my AndroidManifest:
<activity android:name="ws.stefma.projectname.TestFrag" />
Update:
I have import the support-v4 libary.
My AndroidManifest was declared to minSdk="14" and targetSdk="17".
Because i used the support-v4 I have imported on the Fragment-Class
import android.app.support.v4.Fragment
Now i have changed that to
import android.app.Fragment
and it seems to work...
Also i must change the FragmentActivity to Activity. Because the FragmentActivity is only an Class for the support v4 Package!
Update 2 - Solution found:
Here is the solution
Change R.layout.frag_main to something like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="#+id/fragment1"
android:name="ws.stefma.projectname.Frag1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I think you don't need use support-v4 library. Please tell me why do you use that library? I see min sdk is 14, in this case using of sopport-v4 is useless.
Please checkout ws.stefma.projectname package, because logcat says that ws.stefma.projectname.TestFrag doesn't exist.
Okay guys, here is the Solution.
I donn't know exactly what the folling stands for and what it makes, but it runs and i have now errors after these workaround:
Close eclipse -> remove support-V4 -> open eclipse -> right click on your project -> AndroidTools -> Add Support Libary -> right click on your project -> Properties -> Choose java build path -> Choose 'Order and Export' -> Select All -> Click 'ok' -> Project -> Clean -> Run and stay happy!
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" />