I am a beginning in trying to create applications for android using Eclipse (also why i didn't do pictures). I started to learn to program by following Site (link). I tried this 3 times and each times it creates 2 projects. First one always called 'appcompat_v7' and the second one what ever i called it. In this instance I called it 'FirstApp'. In the project FirstApp, I could not find /res/layout containing anything so i created it, calling it fragment_main.xml. Containing:
<?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="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
</LinearLayout>
I edited my 'androidmanifest.xml' to say:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And my strings.xml says:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">FirstApp</string>
<string name="edit_message">Enter a message</string>
</resources>
When running on my Samsung Galaxy S4 or on a AVD manager:
(settings are platform: 4.4W , API Lvl: 20 , and CPU/ABI: Android Wear
ARM (armeabi-v7a) , Device: Nexus 5)
Both give me the same error. "Unfortunately, (app name) has stopped."
And my LogCat gives me this log:
~Not late-enabling CheckJNI (already on)
~Shutting down VM
~threadid=1: thread exiting with uncaught exception (group=0xb2aa9d70)
~FATAL EXCEPTION: main
~Process: com.example.firstapp, PID: 745
~java.lang.RuntimeException: Unable to instantiate activity ComponentI
nfo{com.example.firstapp/com.example.firstapp.MainActivity}: java.lan
g.ClassNotFoundException: Didn't find class "com.example.firstapp.Mai
nActivity" on path: DexPathList[[zip file "/data/app/com.example.firs
tapp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firs
tapp-2, /system/lib]]
~at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2123)
~at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
~at android.app.ActivityThread.access$800(ActivityThread.java:138)
~at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
~at android.os.Handler.dispatchMessage(Handler.java:102)
~at android.os.Looper.loop(Looper.java:136)
~at android.app.ActivityThread.main(ActivityThread.java:5026)
~at java.lang.reflect.Method.invokeNative(Native Method)
~at java.lang.reflect.Method.invoke(Method.java:515)
~at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
~at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
~at dalvik.system.NativeStart.main(Native Method)
~Caused by: java.lang.ClassNotFoundException: Didn't find class "com.e
xample.firstapp.MainActivity" on path: DexPathList[[zip file "/data/a
pp/com.example.firstapp-2.apk"],nativeLibraryDirectories=[/data/app-l
ib/com.example.firstapp-2, /system/lib]]
~at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
~at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
~at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
~at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
~at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
~ ... 11 more
~Sending signal. PID: 745 SIG: 9
I have not edited anything else, but those xml files (strings.xml, fragment_main.xml, and AndroidManifest.xml)
Here is a pic of my packages:
Please help to remove this error. Thanks!
First of all, the reason that your app is creating two projects is for compatibility with devices running below API 14. I would recommend (and this is just a personal preference) that, as a beginner, when you create your projects you should set the minimum API level to 14.
When setting up a new project, check the check box that says 'Create activity', right under 'Create custom launcher icon':
Among the automatically created files, you should find a MainActivity.java file (in src > com.example.YourAppName) and an activity_main.xml layout file (in res > layout). If they are not created, this points to issues with your Eclipse/ADT/SDK setup.
So my advice would be to create a new project (above API 14) and run it without editing/creating any files. If it works, then you're good to go.
Related
This question already has answers here:
Error Inflating class fragment in activity maps xml
(3 answers)
Closed 6 years ago.
I just wanted to run a simple map fragment but I keep getting InflateException. I also asked a similar question but I made a new Google Maps project for simplicity.
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: Process: com.example.ali.myapplication, PID: 1785
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ali.myapplication/com.example.ali.myapplication.MapsActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
MapsActivity.java:
package com.example.ali.myapplication;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
activity_maps.xml:
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#619ec9"
xmlns:android="http://schemas.android.com/apk/res/android">
>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map" tools:context=".MapsActivity"
class="com.google.android.gms.maps.SupportMapFragment"
tools:layout="#layout/activity_maps"
android:layout_width="362dp"
android:layout_height="323dp"
/>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ali.myapplication" >
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Fragment should be added to a frame layour, it cant be directly used.
Update your code and let me know if works
I have the launch activity called MainActivity that will eventually start another called SearchResultsActivity.
They both extend ActionBarActivity, and the second is yet to be written, for now it is just a stub with:
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.search_results);
}
The layout XML is as follows, just a ListView in a white background:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/list_products"
android:layout_gravity="center_horizontal" />
</LinearLayout>
The app is crashing on setContentView() with the following logcat:
17348-17348/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.SearchResultsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1682)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:940)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3714)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
at com.example.myapp.SearchResultsActivity.onCreate(SearchResultsActivity.java:42) <-- this is setContentView()
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1630)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1682)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:940)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3714)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Here's the manifest excerpt:
<activity
android:name="com.example.myapp.MainActivity"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Styled">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myapp.SearchResultsActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Styled"
android:configChanges="orientation|keyboardHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myapp.MainActivity" />
</activity>
I thought it could be some issue with the layout, but then I decide to replace R.layout.search_results with R.layout.home, which is the same XML used in MainActivity, therefore should work. But it crashes in the very same line.
Any ideas on what could be causing this?
As others have pointed out, your error is likely in your onCreate code for your second activity. If you read the documentation here you'll see they start their activity off with onCreate and an immediate call back to super.onCreate(...)
Your code should be as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //added this line
setContentView(R.layout.search_results);
}
If you chose to have your IDE automatically generate an Activity stub, it will always place the call to super.onCreate in your activity. It initializes the activity, see this question for more of an explanation.
If this doesn't fix your problem and you have more code in your second activity, it might be useful to post code for the entire activity.
I'm trying to display google map on my android app when user click on a button.
when I click the button the app stops.No error in the code.
I believe I've done everything right
1-I got the API KEY
2-I added the Google_Play_Services_lib.jar to the dependencies folder
3-added extra support tool
4-included the permissions,my key to the manifest
5-added fragment to my xml layout fie for the map
please help I feel like I've read and watched every tutorial there is...nothing worked!
My Log:
03-10 20:27:10.057: I/Process(17287): Sending signal. PID: 17287 SIG: 9
03-10 20:27:15.072: D/libEGL(17688): loaded /vendor/lib/egl/libEGL_adreno.so
03-10 20:27:15.072: D/libEGL(17688): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
03-10 20:27:15.082: D/libEGL(17688): loaded /vendor/lib/egl/libGLESv2_adreno.so
03-10 20:27:15.082: I/Adreno-EGL(17688): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: (CL4169980)
03-10 20:27:15.082: I/Adreno-EGL(17688): OpenGL ES Shader Compiler Version: 17.01.10.SPL
03-10 20:27:15.082: I/Adreno-EGL(17688): Build Date: 09/26/13 Thu
03-10 20:27:15.082: I/Adreno-EGL(17688): Local Branch:
03-10 20:27:15.082: I/Adreno-EGL(17688): Remote Branch:
03-10 20:27:15.082: I/Adreno-EGL(17688): Local Patches:
03-10 20:27:15.082: I/Adreno-EGL(17688): Reconstruct Branch:
03-10 20:27:15.122: D/OpenGLRenderer(17688): Enabling debug mode 0
03-10 20:27:16.683: D/AndroidRuntime(17688): Shutting down VM
03-10 20:27:16.683: W/dalvikvm(17688): threadid=1: thread exiting with uncaught exception (group=0x41931898)
03-10 20:27:16.693: E/AndroidRuntime(17688): FATAL EXCEPTION: main
03-10 20:27:16.693: E/AndroidRuntime(17688): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newandroid/com.example.newandroid.Mymap}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-10 20:27:16.693: E/AndroidRuntime(17688): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
03-10 20:27:16.693: E/AndroidRuntime(17688): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
03-10 20:27:16.693: E/AndroidRuntime(17688): at android.app.ActivityThread.access$700(ActivityThread.java:159)
My code for Mymap activity
p
ackage com.example.newandroid;
import android.os.Bundle;
//import android.app.Activity;
import android.support.v4.app.FragmentActivity;
public class Mymap extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mymap);
}
}
My layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.newandroid"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.newandroid.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newandroid.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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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" >
<activity android:name="MainActivity">
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.newandroid.Mymap"
android:label="#string/title_activity_mymap"
android:parentActivityName="com.example.newandroid.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.newandroid.MainActivity" />
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAq44a-wWB4W6muJJqZ1DMH-livYscbiyk"/>
</application>
</manifest>
this is the MainActivity where the button is ,when clicked it should start Mymap activity.this is Mainactivity code
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// TODO Auto-generated method stub
}
public void view_map(View view) {
Intent intent = new Intent(this, Mymap.class);
startActivity(intent);
// Do something in response to button
}
}
have you tried to look at this SO post?
seems like changing the xml to match your class name fixes most issues.
Google Maps V2 - Error inflating class Fragment
If you are targeting api level 8 and above then you can't use a simple Activity, you need to extend FragmentActivity.
I'm guessing this is the reason you have the inflating problem.
And you are missing this meta-data section in you manifest file:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
place it next to your's api key meta-data section.
I did use Google Maps v2 API for android in my recent app development and I cannot even start to tell you how long it took to just have the map show up on the screen. I eventually got it working and I have the project on Github which you can look through and make sure to read through all the important files like Manifest and res/ folder;
Google Maps API (Android) v2 Fragment Issues
I hope it helps!
So essentially I've been making a game using libgdx and just recently I started to try and add Google Play Game Services and So I tried my hand at it and it seems as though I have completely messed up my .xml file I've tried looking at questions such as How do I resolve this Java Class not found exception? and NoClassDefFoundError - Eclipse and Android, but to no avail.
Here is the runtime error I am recieving.
02-19 19:25:17.772: E/AndroidRuntime(25746): FATAL EXCEPTION: main
02-19 19:25:17.772: E/AndroidRuntime(25746): Process: com.coppercow.minerman, PID: 25746
02-19 19:25:17.772: E/AndroidRuntime(25746): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.coppercow.minerman/com.coppercow.minerman.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.coppercow.minerman.MainActivity" on path: DexPathList[[zip file "/data/app/com.coppercow.minerman-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.coppercow.minerman-2, /vendor/lib, /system/lib]]
The class Name is MainActivity.Java and it is in the src file. I understand that this is done because of one of two things: My .class file, or the .xml file. So here is also my .xml file just in case what I have done wrong is there and not in fact in any .class file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coppercow.minerman"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
However I've messed around with this xml file quite a lot and so I do not believe it is in here and that My whole problem has to be in some .class file somewhere, but I don't even understand how to access those from eclipse from going off of other questions asked here on StackOverflow.
Try this:
Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it.Mark all checkboxes and Click on Apply and clean the project.
Hope this helps.
I'm having trouble opening an activity. In my first activity (activity_main), I have 3 buttons.
<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:stretchColumns="1">
<TableLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FFFF"
android:id="#+id/root"
>
<TableRow android:layout_margin="0dip"
android:id="#+id/row1">
<Button android:id="#+id/button01"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_weight="1"
android:hint="#string/buttonText1"
android:layout_marginTop="60dip"
android:layout_marginBottom="15dip"
android:padding="15dip" />
</TableRow>
<TableRow android:layout_margin="0dip"
android:id="#+id/row2">
<Button android:id="#+id/button02"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_weight="1"
android:hint="#string/buttonText2"
android:padding="15dip" />
</TableRow>
<TableRow android:layout_margin="0dip"
android:id="#+id/row3">
<Button android:id="#+id/button03"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_marginTop="15dip"
android:hint="#string/buttonText3"
android:onClick="browseExercises"
android:padding="15dip" />
</TableRow>
</TableLayout>
</LinearLayout>
I click on the 3rd button, and my second activity opens, which consists of two additional buttons.
<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:stretchColumns="1">
<TableLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FFFF"
android:id="#+id/root"
>
<TableRow android:layout_margin="0dip"
android:id="#+id/row1">
<Button android:id="#+id/button01"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_weight="1"
android:hint="#string/alphabetical"
android:layout_marginTop="60dip"
android:layout_marginBottom="15dip"
android:onClick="Alphabetical"
android:padding="15dip" />
</TableRow>
<TableRow android:layout_margin="0dip"
android:id="#+id/row2">
<Button android:id="#+id/button99999"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_weight="1"
android:hint="#string/group"
android:onClick="muscleGroups"
android:padding="15dip" />
</TableRow>
</TableLayout>
</LinearLayout>
I click on either of these buttons, and I get an error telling me that "Unfortunately, Test_Project has stopped."
I already have an activity created for each of these two buttons, and everything for these two buttons are coded the exact same way as when I created my second activity, which opens just fine, and has buttons I can click on without causing any errors. I think I'm missing something fundamental here, it's like if I create too many activities, they aren't able to look back at my MainActivity.java file for the method that is supposed to open the next activity. Here is my MainActivity.java code:
package com.example.test_project;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void browseExercises(View view){
Intent intent = new Intent(this, BrowseExercises.class);
startActivity(intent);
}
public void Alphabetical(View view){
Intent intent = new Intent(this, Alphabetical.class);
startActivity(intent);
}
public void muscleGroups(View view){
Intent intent = new Intent(this, MuscleGroups.class);
startActivity(intent);
}
#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;
}
}
Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test_project"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test_project.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.test_project.BrowseExercises"
android:label="#string/title_activity_browse_exercises"
>
</activity>
<activity
android:name="com.example.test_project.MuscleGroups"
android:label="#string/title_activity_muscle_groups" >
</activity>
<activity
android:name="com.example.test_project.Alphabetical"
android:label="#string/title_activity_alphabetical" >
</activity>
</application>
</manifest>
And my logcat file:
04-20 13:46:57.632: W/dalvikvm(26747): threadid=1: thread exiting with uncaught exception (group=0x40dc42a0)
04-20 13:46:57.639: E/AndroidRuntime(26747): FATAL EXCEPTION: main
04-20 13:46:57.639: E/AndroidRuntime(26747): java.lang.IllegalStateException: Could not find a method muscleGroups(View) in the activity class com.example.test_project.BrowseExercises for onClick handler on view class android.widget.Button with id 'button99999'
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.view.View$1.onClick(View.java:3587)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.view.View.performClick(View.java:4106)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.view.View$PerformClick.run(View.java:17052)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.os.Handler.handleCallback(Handler.java:615)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.os.Handler.dispatchMessage(Handler.java:92)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.os.Looper.loop(Looper.java:137)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.app.ActivityThread.main(ActivityThread.java:5059)
04-20 13:46:57.639: E/AndroidRuntime(26747): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 13:46:57.639: E/AndroidRuntime(26747): at java.lang.reflect.Method.invoke(Method.java:511)
04-20 13:46:57.639: E/AndroidRuntime(26747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
04-20 13:46:57.639: E/AndroidRuntime(26747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
04-20 13:46:57.639: E/AndroidRuntime(26747): at dalvik.system.NativeStart.main(Native Method)
04-20 13:46:57.639: E/AndroidRuntime(26747): Caused by: java.lang.NoSuchMethodException: muscleGroups [class android.view.View]
04-20 13:46:57.639: E/AndroidRuntime(26747): at java.lang.Class.getConstructorOrMethod(Class.java:460)
04-20 13:46:57.639: E/AndroidRuntime(26747): at java.lang.Class.getMethod(Class.java:915)
04-20 13:46:57.639: E/AndroidRuntime(26747): at android.view.View$1.onClick(View.java:3580)
04-20 13:46:57.639: E/AndroidRuntime(26747): ... 11 more
04-20 13:46:59.202: I/Process(26747): Sending signal. PID: 26747 SIG: 9
Probably something pretty simple I'm just not aware of yet, but any help would be appreciated!!!!
By looking at your comment I guess that you have not created JAVA files for other Activities.
For e.g. you must create BrowseExercise.java file in the directory where your main Activity lies. And then you need to define this Activity in the AndroidManifest.xml file.
An easy way to do is by just clicking +(or something like that) on left TOP corner , then Android , New Activity . Then you just have to select which type of activity you want to use .
Have you made Java files for all your activity? Like if you are opening other activity it should fulfill following requirements:
It should be mention in manifest file with proper action
There should be one java file corresponding to that activity
Layout file should be defined or you should create layout via code
Intent should be properly declared.
If still problem exists please add more code of your intent calling and java files.