[Q] Error - Google Maps Android API v2 - Java for Android App Development

Helllo
I have a problem with Google Maps Android API v2
every time I try to open the app on device or even on emulator this message always display
Unfortunately Google Maps API Demos has stopped
I have made a video that Explain every steps that I did
http://www.youtube.com/watch?v=WUmlu3CNOSo
and this is the error that display on Eclipse
ahmadssb.com/ttv2541/com.example.mapdemo.txt
Actually I have tried many tutorials on internet
also I tried to do the coding by myself according to Google instructions
https://developers.google.com/maps/documentation/android/start
and this is the error that display on Eclipse
www.ahmadssb.com/ttv2541/com.example.mapdemo.txt
I don't know what's wrong with this problem
please help me

ahmadssb said:
Helllo
I have a problem with Google Maps Android API v2
every time I try to open the app on device or even on emulator this message always display
Unfortunately Google Maps API Demos has stopped
I have made a video that Explain every steps that I did
http://www.youtube.com/watch?v=WUmlu3CNOSo
and this is the error that display on Eclipse
ahmadssb.com/ttv2541/com.example.mapdemo.txt
Actually I have tried many tutorials on internet
also I tried to do the coding by myself according to Google instructions
https://developers.google.com/maps/documentation/android/start
and this is the error that display on Eclipse
www.ahmadssb.com/ttv2541/com.example.mapdemo.txt
I don't know what's wrong with this problem
please help me
Click to expand...
Click to collapse
Your package name is com.*.
I think that in your AndroidManifest.xml there is a "L" before the com in the definition of your class. It is something like Lcom.*
Remove the L.

My suggestion is to walk through the following tutorial and see if you can get it working and put the demo to the side for now.
http://www.vogella.com/articles/AndroidGoogleMaps/article.html

nikwen said:
Your package name is com.*.
I think that in your AndroidManifest.xml there is a "L" before the com in the definition of your class. It is something like Lcom.*
Remove the L.
Click to expand...
Click to collapse
there is no L on package name ...
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="2"
android:versionName="2.1.0">
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- End of copy. -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/demo_title"
android:hardwareAccelerated="true">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".BasicMapActivity"
android:label="@string/basic_map"/>
<activity
android:name=".CameraDemoActivity"
android:label="@string/camera_demo"/>
<activity
android:name=".CircleDemoActivity"
android:label="@string/circle_demo"/>
<activity
android:name=".EventsDemoActivity"
android:label="@string/events_demo"/>
<activity
android:name=".GroundOverlayDemoActivity"
android:label="@string/groundoverlay_demo"/>
<activity
android:name=".LayersDemoActivity"
android:label="@string/layers_demo"/>
<activity
android:name=".LocationSourceDemoActivity"
android:label="@string/locationsource_demo"/>
<activity
android:name=".MarkerDemoActivity"
android:label="@string/marker_demo"/>
<activity
android:name=".OptionsDemoActivity"
android:label="@string/options_demo"/>
<activity
android:name=".PolygonDemoActivity"
android:label="@string/polygon_demo"/>
<activity
android:name=".PolylineDemoActivity"
android:label="@string/polyline_demo"/>
<activity
android:name=".ProgrammaticDemoActivity"
android:label="@string/programmatic_demo"/>
<activity
android:name=".TileOverlayDemoActivity"
android:label="@string/tile_overlay_demo"/>
<activity
android:name=".UiSettingsDemoActivity"
android:label="@string/uisettings_demo"/>
<activity
android:name=".RawMapViewDemoActivity"
android:label="@string/raw_mapview_demo"/>
<activity
android:name=".RetainMapActivity"
android:label="@string/retain_map"/>
<activity
android:name=".MultiMapDemoActivity"
android:label="@string/multi_map_demo"/>
</application>
</manifest>
MainActivity.java
Code:
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.mapdemo;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.example.mapdemo.view.FeatureView;
/**
* The main activity of the API library demo gallery.
* <p>
* The main layout lists the demonstrated features, with buttons to launch them.
*/
public final class MainActivity extends ListActivity {
/**
* A simple POJO that holds the details about the demo that are used by the List Adapter.
*/
private static class DemoDetails {
/**
* The resource id of the title of the demo.
*/
private final int titleId;
/**
* The resources id of the description of the demo.
*/
private final int descriptionId;
/**
* The demo activity's class.
*/
private final Class<? extends FragmentActivity> activityClass;
public DemoDetails(
int titleId, int descriptionId, Class<? extends FragmentActivity> activityClass) {
super();
this.titleId = titleId;
this.descriptionId = descriptionId;
this.activityClass = activityClass;
}
}
/**
* A custom array adapter that shows a {@link FeatureView} containing details about the demo.
*/
private static class CustomArrayAdapter extends ArrayAdapter<DemoDetails> {
/**
* [user=955119]@param[/user] demos An array containing the details of the demos to be displayed.
*/
public CustomArrayAdapter(Context context, DemoDetails[] demos) {
super(context, R.layout.feature, R.id.title, demos);
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
FeatureView featureView;
if (convertView instanceof FeatureView) {
featureView = (FeatureView) convertView;
} else {
featureView = new FeatureView(getContext());
}
DemoDetails demo = getItem(position);
featureView.setTitleId(demo.titleId);
featureView.setDescriptionId(demo.descriptionId);
return featureView;
}
}
private static final DemoDetails[] demos = {new DemoDetails(
R.string.basic_map, R.string.basic_description, BasicMapActivity.class),
new DemoDetails(R.string.camera_demo, R.string.camera_description,
CameraDemoActivity.class),
new DemoDetails(R.string.events_demo, R.string.events_description,
EventsDemoActivity.class),
new DemoDetails(R.string.layers_demo, R.string.layers_description,
LayersDemoActivity.class),
new DemoDetails(
R.string.locationsource_demo, R.string.locationsource_description,
LocationSourceDemoActivity.class),
new DemoDetails(R.string.uisettings_demo, R.string.uisettings_description,
UiSettingsDemoActivity.class),
new DemoDetails(R.string.groundoverlay_demo, R.string.groundoverlay_description,
GroundOverlayDemoActivity.class),
new DemoDetails(R.string.marker_demo, R.string.marker_description,
MarkerDemoActivity.class),
new DemoDetails(R.string.polygon_demo, R.string.polygon_description,
PolygonDemoActivity.class),
new DemoDetails(R.string.polyline_demo, R.string.polyline_description,
PolylineDemoActivity.class),
new DemoDetails(R.string.circle_demo, R.string.circle_description,
CircleDemoActivity.class),
new DemoDetails(R.string.tile_overlay_demo, R.string.tile_overlay_description,
TileOverlayDemoActivity.class),
new DemoDetails(R.string.options_demo, R.string.options_description,
OptionsDemoActivity.class),
new DemoDetails(R.string.multi_map_demo, R.string.multi_map_description,
MultiMapDemoActivity.class),
new DemoDetails(R.string.retain_map, R.string.retain_map_description,
RetainMapActivity.class),
new DemoDetails(R.string.raw_mapview_demo, R.string.raw_mapview_description,
RawMapViewDemoActivity.class),
new DemoDetails(R.string.programmatic_demo, R.string.programmatic_description,
ProgrammaticDemoActivity.class)};
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListAdapter adapter = new CustomArrayAdapter(this, demos);
setListAdapter(adapter);
}
[user=439709]@override[/user]
protected void onListItemClick(ListView l, View v, int position, long id) {
DemoDetails demo = (DemoDetails) getListAdapter().getItem(position);
startActivity(new Intent(this, demo.activityClass));
}
}

zalez said:
My suggestion is to walk through the following tutorial and see if you can get it working and put the demo to the side for now.
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Click to expand...
Click to collapse
It does not find the class definition because the path is spelled wrong!

nikwen said:
It does not find the class definition because the path is spelled wrong!
Click to expand...
Click to collapse
Incorrect. The "L" means Link.
http://stackoverflow.com/questions/13733911/google-maps-android-api-v2-sample-code-crashes

zalez said:
My suggestion is to walk through the following tutorial and see if you can get it working and put the demo to the side for now.
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Click to expand...
Click to collapse
I tried his tutorial and I still same error displayed
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vogella.android.locationapi.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.vogella.android.locationapi.maps.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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.vogella.android.locationapi.maps.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value=".................................................." />
</application>
</manifest>
ShowMapActivity.java
Code:
package com.vogella.android.locationapi.maps;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class ShowMapActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.show_map, menu);
return true;
}
}
Error Log
Code:
04-24 05:09:39.576: E/Trace(10600): error opening trace file: No such file or directory (2)
04-24 05:09:39.741: D/dalvikvm(10600): Trying to load lib /data/app-lib/com.google.android.gms-2/libAppDataSearch.so 0x4215ea30
04-24 05:09:39.806: D/dalvikvm(10600): Added shared lib /data/app-lib/com.google.android.gms-2/libAppDataSearch.so 0x4215ea30
04-24 05:09:39.806: D/dalvikvm(10600): No JNI_OnLoad found in /data/app-lib/com.google.android.gms-2/libAppDataSearch.so 0x4215ea30, skipping init
04-24 05:09:39.811: D/Icing(10600): Init last flush num docs 170 last docstore size 431104
04-24 05:09:39.811: D/Icing(10600): Docid map file has data, scanning...
04-24 05:09:39.811: D/Icing(10600): Scanning /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.docids found 170 documents, last docstore location 429312
04-24 05:09:39.811: D/Icing(10600): File /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.perdocdata contains 170 records of size 6
04-24 05:09:39.816: D/Icing(10600): Init docstore ok num docs 170 bytes 431104
04-24 05:09:39.831: V/Icing(10600): Lite index crc computed in 0.079ms
04-24 05:09:39.831: V/Icing(10600): Lite index init ok in 1.932ms
04-24 05:09:39.831: V/Icing(10600): Warming lite-index took 0.011ms
04-24 05:09:39.831: V/Icing(10600): Warming lexicon took 0.020ms
04-24 05:09:39.831: V/Icing(10600): Warming display mappings took 0.012ms
04-24 05:09:39.831: D/Icing(10600): Init index ok num docs 170
04-24 05:09:39.831: D/Icing(10600): Init done
04-24 05:09:39.866: E/Icing(10600): Not enough disk space. Will not index.
04-24 05:09:57.391: I/Recovery(10600): Received: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.recovery.AccountRecoveryService$Receiver }
04-24 05:09:57.806: I/Recovery(10600): Received: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.recovery.AccountRecoveryService$Receiver }
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}

04-24 05:09:39.866: E/Icing(10600): Not enough disk space. Will not index.
are you out of space?

out of ideas said:
04-24 05:09:39.866: E/Icing(10600): Not enough disk space. Will not index.
are you out of space?
Click to expand...
Click to collapse
i didn't understand what this error means or want !!! because I have more than enough space for simple program like this
if it means my PC then I have more than enough space on my SSD hard drive and RAM is 8 GB
also when I check the task manege
RAM : 61%
CPU almost 18%
and for my phone (GS2 using CyanogenMod 10.1):
System ROM: 528 MB (159 MB free)
Internal : 2.11 GB (886 MB free)
media : 12.3 GB (4.8 GB free)
Ext. SD card : 15.7 GB (14.5 GB free)

weird. are you still getting the same fatal exception error?
So, your activity where the map is should extend a fragment activity cuz the maps are now fragments. You should also go with SupportMapFragment so gingerbread can use it too.
im using something like this for my MainActivity
Code:
import android.support.v4.app.FragmentActivity;
import android.view.View;
//There are other imports, these are map things
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
//Notice the FragmentActivity difference?
public class MainActivity extends FragmentActivity {
private GoogleMap mMap;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
and then my layout that gets setup from there is like this
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
this site has some good tutorials on the maps. I couldnt get vogella to work for me either.
http://wptrafficanalyzer.in/blog/go...maps-android-api-v2-using-supportmapfragment/

out of ideas said:
weird. are you still getting the same fatal exception error?
So, your activity where the map is should extend a fragment activity cuz the maps are now fragments. You should also go with SupportMapFragment so gingerbread can use it too.
im using something like this for my MainActivity
Code:
import android.support.v4.app.FragmentActivity;
import android.view.View;
//There are other imports, these are map things
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
//Notice the FragmentActivity difference?
public class MainActivity extends FragmentActivity {
private GoogleMap mMap;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
and then my layout that gets setup from there is like this
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
this site has some good tutorials on the maps. I couldnt get vogella to work for me either.
http://wptrafficanalyzer.in/blog/go...maps-android-api-v2-using-supportmapfragment/
Click to expand...
Click to collapse
thank you for the link, but I still getting the same error in my phone (Galaxy S 2, ROM CyanogenMod 10.1 )
also using the emulator with 2 AVD for (4.2.2) and (4.2.2 with Google API)
still not working
I start to think (and maybe it is ) that the problem is not from the code the problem is from my phone or the setting in my PC or Eclipse
while any other application is working fine with me except that using google apis key (actually I didn't try any thing that needs api key and this is my first time using it)
BTW this is the result from the tutorial from the link that you gave to me
====================================================
Log:
——-
Code:
04-26 01:28:57.494: D/dalvikvm(5121): Late-enabling CheckJNI
04-26 01:28:57.629: E/Trace(5121): error opening trace file: No such file or directory (2)
04-26 01:28:57.659: D/AndroidRuntime(5121): Shutting down VM
04-26 01:28:57.659: W/dalvikvm(5121): threadid=1: thread exiting with uncaught exception (group=0x41ff7930)
04-26 01:28:57.679: E/AndroidRuntime(5121): FATAL EXCEPTION: main
04-26 01:28:57.679: E/AndroidRuntime(5121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmadssb.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Looper.loop(Looper.java:137)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.main(ActivityThread.java:5226)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.NativeStart.main(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
04-26 01:28:57.679: E/AndroidRuntime(5121): … 11 more
——
AndroidManifest.xml
——-
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmadssb.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.ahmadssb.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.ahmadssb.locationgooglemapv2demo.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-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="in.wptrafficanalyzer.locationgooglemapv2demo.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="************MY API KEY***********"/>
</application>
</manifest>
——-
MainActivity.java
———-
Code:
package com.ahmadssb.locationgooglemapv2demo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
[user=439709]@override[/user]
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;
}
}
——
activity_main.xml
———-
<
Code:
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 xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
———–

If I get some time, I will try the demo out to help more. I created my google maps app back before you had to import the library.
To me, your manifest looks off.
Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
[B] package="com.ahmadssb.locationgooglemapv2demo"[/B]
android:versionCode="1"
android:versionName="1.0" >
The bold is your package. When you define your activity name, it should either resemble your package plus your activity name. Your activity name doesn't look right (Look at below code).
Code:
<activity
android:name="[B]in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity[/B]"
android:label="@string/app_name" >
You should fix your activity name in your manifest first. Get rid of "in.wptrafficanalyzer.locationgooglemapv2demo" and just leave ".MainActivity" (be sure to leave the period in front of it)

ahmadssb said:
thank you for the link, but I still getting the same error in my phone (Galaxy S 2, ROM CyanogenMod 10.1 )
also using the emulator with 2 AVD for (4.2.2) and (4.2.2 with Google API)
still not working
I start to think (and maybe it is ) that the problem is not from the code the problem is from my phone or the setting in my PC or Eclipse
while any other application is working fine with me except that using google apis key (actually I didn't try any thing that needs api key and this is my first time using it)
BTW this is the result from the tutorial from the link that you gave to me
====================================================
Log:
——-
Code:
04-26 01:28:57.494: D/dalvikvm(5121): Late-enabling CheckJNI
04-26 01:28:57.629: E/Trace(5121): error opening trace file: No such file or directory (2)
04-26 01:28:57.659: D/AndroidRuntime(5121): Shutting down VM
04-26 01:28:57.659: W/dalvikvm(5121): threadid=1: thread exiting with uncaught exception (group=0x41ff7930)
04-26 01:28:57.679: E/AndroidRuntime(5121): FATAL EXCEPTION: main
04-26 01:28:57.679: E/AndroidRuntime(5121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmadssb.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Looper.loop(Looper.java:137)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.main(ActivityThread.java:5226)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.NativeStart.main(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
04-26 01:28:57.679: E/AndroidRuntime(5121): … 11 more
——
You're getting closer
you got enough space, now you're error is this
Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679:
You changed the name of your package, but left the references from the tutorial the same.
switch EVERYTHING that says "in.wptrafficanalyzer....." etc. and change them to "com.ahmadssb......"
the api key stuff doesn't really matter till you get it up and running. If you typed in the wrong api key, your program would still load normally, but you just get a gray background where the map should be.
Click to expand...
Click to collapse
Click to expand...
Click to collapse
Click to expand...
Click to collapse

out of ideas said:
ahmadssb said:
thank you for the link, but I still getting the same error in my phone (Galaxy S 2, ROM CyanogenMod 10.1 )
also using the emulator with 2 AVD for (4.2.2) and (4.2.2 with Google API)
still not working
I start to think (and maybe it is ) that the problem is not from the code the problem is from my phone or the setting in my PC or Eclipse
while any other application is working fine with me except that using google apis key (actually I didn't try any thing that needs api key and this is my first time using it)
BTW this is the result from the tutorial from the link that you gave to me
====================================================
Log:
——-
Code:
04-26 01:28:57.494: D/dalvikvm(5121): Late-enabling CheckJNI
04-26 01:28:57.629: E/Trace(5121): error opening trace file: No such file or directory (2)
04-26 01:28:57.659: D/AndroidRuntime(5121): Shutting down VM
04-26 01:28:57.659: W/dalvikvm(5121): threadid=1: thread exiting with uncaught exception (group=0x41ff7930)
04-26 01:28:57.679: E/AndroidRuntime(5121): FATAL EXCEPTION: main
04-26 01:28:57.679: E/AndroidRuntime(5121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmadssb.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Looper.loop(Looper.java:137)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.main(ActivityThread.java:5226)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.NativeStart.main(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
04-26 01:28:57.679: E/AndroidRuntime(5121): … 11 more
——
You're getting closer
you got enough space, now you're error is this
Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679:
You changed the name of your package, but left the references from the tutorial the same.
switch EVERYTHING that says "in.wptrafficanalyzer....." etc. and change them to "com.ahmadssb......"
the api key stuff doesn't really matter till you get it up and running. If you typed in the wrong api key, your program would still load normally, but you just get a gray background where the map should be.
Click to expand...
Click to collapse
thanks for the help
It works now but not after fix the package name only
but I did some modification and organization for libraries something at top and rest bottom also copy the libraries to workplace not use it from the android directory
Actually I don't know exactly how did this works but finally it works :victory:
thank you all for your help
Click to expand...
Click to collapse
Click to expand...
Click to collapse
Click to expand...
Click to collapse

Related

Help creating a simple calculator!

Hello everyone I tried creating a simple calculator but when opening in my LWW it just force closes , so I am attaching the xmls and .java codes for your ready reference.
I am well versed in netbeans programming but new to android hence a helpful post will be really appreciated!
Bullet
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtNum1;
private EditText txtNum2;
private EditText txtAns;
double a = Double.parseDouble(txtNum1.getText().toString()) ;
double b = Double.parseDouble(txtNum2.getText().toString());
double c=0;
public void add(double a,double b)
{
c=a+b;
txtAns.setText(""+c);
return;
}
public void sub(double a,double b)
{
c=a-b;
txtAns.setText(""+c);
return;
}
public void div(double a,double b)
{
if(b==0)
{
txtAns.setText("Number 2 can't be 0!");
}
else{
c=a/b;
txtAns.setText(""+c);
return;
}
}
public void mul(double a,double b)
{
c=a*b;
txtAns.setText(""+c);
return;
}
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
[user=439709]@override[/user]
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;
}
}
strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CalcPlus</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btnPlus">+</string>
<string name="btnSub">-</string>
<string name="btnMul">*</string>
<string name="btnDiv">/</string>
<string name="txtNum2">Enter number 2 here</string>
<string name="txtNum1">Enter number 1 here</string>
<string name="txtAns">Result</string>
</resources>
activity_main.xml
Code:
<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=".MainActivity" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnMul"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btnSub"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnPlus"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnDiv"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txtNum2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txtNum1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/btnDiv"
android:layout_below="@+id/btnMul"
android:layout_marginTop="40dp"
android:ems="10"
android:enabled="false"
android:hint="@string/txtAns"
android:linksClickable="false" />
</RelativeLayout>
Manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ptx.calcplus"
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.ptx.calcplus.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hey BULLET, you seem to be on the right track but you've got a bit of tweaking to do.
Firstly, you need to tie all of your UI elements from XML to your activity. Do this in your on create method. My guess is that your force close is due to this line:
Code:
double a = Double.parseDouble(txtNum1.getText().toString()) ;
Your activity has no idea what txtNum1 is tied to, only that it is an EditText object. To set this up properly, keep your global edit text declarations and below is an example of what you'd add to your onCreate method:
Code:
txtNum1 = (EditText) findViewById(R.id.txtNum1);
You would need to do the same for your buttons and all of the elements that you have defined in your XML layout which you want to modify from your activity. (May I also suggest that you use a TextView instead of EditText to display the answer...)
Code:
Button buttonSubtract;
...
protected void onCreate(Bundle savedInstanceState) {
...
buttonSubtract = (Button) findViewById(R.id.btnSub);
...
}
You must also add methods for your buttons to wait for a click and perform the calculation methods you have written. To do this you would set up and onClickListener for each button.
I found TheNewBoston tutorials really handy when starting out. Here is an example of tying together the buttons and actions that they perform. It is very close to what you are trying to do.
http://www.youtube.com/watch?v=WjE-pWYElsE
Hope it helps. Feel free to ask any more questions.
Changed thing in accordance with video but still getting fc.
If possible could anyone paste the correct codes in my style?
BTW here are the code
strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CalcPlus</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btnp">+</string>
<string name="btns">-</string>
<string name="btnm">*</string>
<string name="btnd">/</string>
<string name="txt2">Enter number 2 here</string>
<string name="txt1">Enter number 1 here</string>
<string name="txta">Result</string>
</resources>
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
Button Add,Sub,Div,Mul;
double a=Double.parseDouble(txtN1.getText().toString());
double b=Double.parseDouble(txtN2.getText().toString());
double c=0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add= (Button) findViewById(R.id.btnAdd);
Sub= (Button) findViewById(R.id.btnSub);
Div= (Button) findViewById(R.id.btnDiv);
Mul= (Button) findViewById(R.id.btnMul);
txtN1= (EditText) findViewById(R.id.txtNum1);
txtN2= (EditText) findViewById(R.id.txtNum2);
txtAn= (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
c=a+b;
txtAn.setText(""+c);
}
});
}
[user=439709]@override[/user]
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;
}
}
activity_main.xml
Code:
<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=".MainActivity" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnm"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btns"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnp"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnd"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txt2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txt1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/btnDiv"
android:layout_below="@+id/btnMul"
android:layout_marginTop="40dp"
android:ems="10"
android:enabled="false"
android:hint="@string/txta"
android:linksClickable="false" />
</RelativeLayout>
Please please help me out!
I've fixed it up a little and it runs perfectly on my phone.
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul;
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a + b;
txtAn.setText(""+c);
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
txtAn.setText(""+c);
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a * b;
txtAn.setText(""+c);
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a / b;
txtAn.setText(""+c);
}
});
}
[user=439709]@override[/user]
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;
}
}
activity_main.xml
Code:
<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" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnm"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btns"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnp"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnd"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txt2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txt1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/btnDiv"
android:layout_below="@+id/btnMul"
android:layout_marginTop="40dp"
android:ems="10"
android:enabled="false"
android:hint="@string/txta"
android:linksClickable="false" />
</RelativeLayout>
I haven't touched the other files. Hope you get it working.
Works perfectly thank you.
Just tried to add dialog and clear, exit buttons but getting fc again. Please look into . I am really excited to make my first app.
Thank you once again
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a-b;
txtAn.setText(""+c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a*b;
txtAn.setText(""+c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else if(b==0)
{
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
[user=439709]@override[/user]
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;
}
}
activity_main.xml
Code:
<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" >
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_alignParentLeft="true"
android:text="@string/btnm"
android:onClick="mul" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="127dp"
android:layout_toRightOf="@+id/btnMul"
android:text="@string/btns"
android:onClick="sub" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSub"
android:layout_alignBottom="@+id/btnSub"
android:layout_toRightOf="@+id/btnSub"
android:text="@string/btnp"
android:onClick="add" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnAdd"
android:layout_alignBottom="@+id/btnAdd"
android:layout_toRightOf="@+id/btnAdd"
android:text="@string/btnd"
android:onClick="div"/>
<EditText
android:id="@+id/txtNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnMul"
android:layout_alignLeft="@+id/btnMul"
android:layout_alignRight="@+id/btnDiv"
android:layout_marginBottom="90dp"
android:ems="10"
android:hint="@string/txt2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/txtNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtNum2"
android:layout_alignLeft="@+id/txtNum2"
android:layout_alignRight="@+id/txtNum2"
android:layout_marginBottom="39dp"
android:ems="10"
android:hint="@string/txt1"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtAns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btnMul"
android:ems="10"
android:enabled="false"
android:hint="@string/txta"
android:linksClickable="false" />
<Button
android:id="@+id/btnClr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/btnSub"
android:layout_below="@+id/txtAns"
android:layout_marginTop="21dp"
android:text="@string/btnc"
android:onClick="clr" />
<Button
android:id="@+id/btnExt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnClr"
android:layout_alignRight="@+id/txtAns"
android:text="@string/btne"
android:onClick="ext" />
</RelativeLayout>
Manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ptx.calcplus"
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.ptx.calcplus.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CalcPlus</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btnp">+</string>
<string name="btns">-</string>
<string name="btnm">*</string>
<string name="btnd">/</string>
<string name="txt2">Enter number 2 here</string>
<string name="txt1">Enter number 1 here</string>
<string name="txta">Result</string>
<string name="btnc">Clear</string>
<string name="btne">Exit</string>
</resources>
Please help me out!
Instead of having people fix your errors, how about posting your logcat so we can give you ideas on how to fix them. You won't learn how to debug by having other people do it for you. Also, on your exit button click, all you need to do is "finish();" the activity. You don't need to launch an intent because then your app technically never terminates.
zalez said:
Instead of having people fix your errors, how about posting your logcat so we can give you ideas on how to fix them. You won't learn how to debug by having other people do it for you. Also, on your exit button click, all you need to do is "finish();" the activity. You don't need to launch an intent because then your app technically never terminates.
Click to expand...
Click to collapse
So here is the logcat
Code:
04-23 10:31:20.509: E/Trace(3960): error opening trace file: No such file or directory (2)
04-23 10:32:31.009: E/AndroidRuntime(4130): ... 11 more
This is not the part of the logcat we need.
If you want to finish the activity from the Listener, use that:
Code:
MainActivity.this.finish();
nikwen said:
This is not the part of the logcat we need.
If you want to finish the activity from the Listener, use that:
Code:
MainActivity.this.finish();
Click to expand...
Click to collapse
Pl reply how to get a logcat in eclipse!!
Bullet
[==)BULLET(==] said:
Pl reply how to get a logcat in eclipse!!
Bullet
Click to expand...
Click to collapse
Check this: http://www.youtube.com/watch?v=2AHJsRKa_J8
Will have a closer look at your source code later.
nikwen said:
Check this: http://www.youtube.com/watch?v=2AHJsRKa_J8
Will have a closer look at your source code later.
Click to expand...
Click to collapse
Please put those Log.i(String String); in my code where ever it is appropriate.
Here is the whole logcat. Please help!
04-23 05:36:12.523: E/Trace(831): error opening trace file: No such file or directory (2)
04-23 05:36:12.863: D/AndroidRuntime(831): Shutting down VM
04-23 05:36:12.893: W/dalvikvm(831): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:36:12.953: E/AndroidRuntime(831): FATAL EXCEPTION: main
04-23 05:36:12.953: E/AndroidRuntime(831): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.os.Looper.loop(Looper.java:137)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:36:12.953: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:36:12.953: E/AndroidRuntime(831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:36:12.953: E/AndroidRuntime(831): at dalvik.system.NativeStart.main(Native Method)
04-23 05:36:12.953: E/AndroidRuntime(831): Caused by: java.lang.NullPointerException
04-23 05:36:12.953: E/AndroidRuntime(831): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:36:12.953: E/AndroidRuntime(831): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:36:12.953: E/AndroidRuntime(831): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:36:12.953: E/AndroidRuntime(831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:36:12.953: E/AndroidRuntime(831): ... 11 more
04-23 05:36:38.723: I/Process(831): Sending signal. PID: 831 SIG: 9
04-23 05:36:56.583: D/AndroidRuntime(867): Shutting down VM
04-23 05:36:56.644: W/dalvikvm(867): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:36:56.673: E/AndroidRuntime(867): FATAL EXCEPTION: main
04-23 05:36:56.673: E/AndroidRuntime(867): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.os.Looper.loop(Looper.java:137)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:36:56.673: E/AndroidRuntime(867): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:36:56.673: E/AndroidRuntime(867): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:36:56.673: E/AndroidRuntime(867): at dalvik.system.NativeStart.main(Native Method)
04-23 05:36:56.673: E/AndroidRuntime(867): Caused by: java.lang.NullPointerException
04-23 05:36:56.673: E/AndroidRuntime(867): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:36:56.673: E/AndroidRuntime(867): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:36:56.673: E/AndroidRuntime(867): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:36:56.673: E/AndroidRuntime(867): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:36:56.673: E/AndroidRuntime(867): ... 11 more
04-23 05:37:00.153: I/Process(867): Sending signal. PID: 867 SIG: 9
04-23 05:37:16.343: E/Trace(884): error opening trace file: No such file or directory (2)
04-23 05:37:16.564: D/AndroidRuntime(884): Shutting down VM
04-23 05:37:16.564: W/dalvikvm(884): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:37:16.613: E/AndroidRuntime(884): FATAL EXCEPTION: main
04-23 05:37:16.613: E/AndroidRuntime(884): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.os.Looper.loop(Looper.java:137)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:37:16.613: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:37:16.613: E/AndroidRuntime(884): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:37:16.613: E/AndroidRuntime(884): at dalvik.system.NativeStart.main(Native Method)
04-23 05:37:16.613: E/AndroidRuntime(884): Caused by: java.lang.NullPointerException
04-23 05:37:16.613: E/AndroidRuntime(884): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:37:16.613: E/AndroidRuntime(884): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:37:16.613: E/AndroidRuntime(884): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:37:16.613: E/AndroidRuntime(884): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:37:16.613: E/AndroidRuntime(884): ... 11 more
04-23 05:38:20.383: D/AndroidRuntime(946): Shutting down VM
04-23 05:38:20.383: W/dalvikvm(946): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:38:20.444: E/AndroidRuntime(946): FATAL EXCEPTION: main
04-23 05:38:20.444: E/AndroidRuntime(946): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.os.Looper.loop(Looper.java:137)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:38:20.444: E/AndroidRuntime(946): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:38:20.444: E/AndroidRuntime(946): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:38:20.444: E/AndroidRuntime(946): at dalvik.system.NativeStart.main(Native Method)
04-23 05:38:20.444: E/AndroidRuntime(946): Caused by: java.lang.NullPointerException
04-23 05:38:20.444: E/AndroidRuntime(946): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:38:20.444: E/AndroidRuntime(946): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:38:20.444: E/AndroidRuntime(946): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:38:20.444: E/AndroidRuntime(946): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:38:20.444: E/AndroidRuntime(946): ... 11 more
04-23 05:50:13.903: E/Trace(1245): error opening trace file: No such file or directory (2)
04-23 05:50:14.063: D/AndroidRuntime(1245): Shutting down VM
04-23 05:50:14.103: W/dalvikvm(1245): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:50:14.133: E/AndroidRuntime(1245): FATAL EXCEPTION: main
04-23 05:50:14.133: E/AndroidRuntime(1245): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.os.Looper.loop(Looper.java:137)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:50:14.133: E/AndroidRuntime(1245): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:50:14.133: E/AndroidRuntime(1245): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:50:14.133: E/AndroidRuntime(1245): at dalvik.system.NativeStart.main(Native Method)
04-23 05:50:14.133: E/AndroidRuntime(1245): Caused by: java.lang.NullPointerException
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:50:14.133: E/AndroidRuntime(1245): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:50:14.133: E/AndroidRuntime(1245): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:50:14.133: E/AndroidRuntime(1245): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:50:14.133: E/AndroidRuntime(1245): ... 11 more
04-23 05:50:14.223: I/Process(1245): Sending signal. PID: 1245 SIG: 9
04-23 05:50:24.554: E/Trace(1262): error opening trace file: No such file or directory (2)
04-23 05:50:24.754: D/AndroidRuntime(1262): Shutting down VM
04-23 05:50:24.764: W/dalvikvm(1262): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:50:24.814: E/AndroidRuntime(1262): FATAL EXCEPTION: main
04-23 05:50:24.814: E/AndroidRuntime(1262): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.os.Looper.loop(Looper.java:137)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:50:24.814: E/AndroidRuntime(1262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:50:24.814: E/AndroidRuntime(1262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:50:24.814: E/AndroidRuntime(1262): at dalvik.system.NativeStart.main(Native Method)
04-23 05:50:24.814: E/AndroidRuntime(1262): Caused by: java.lang.NullPointerException
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:50:24.814: E/AndroidRuntime(1262): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:50:24.814: E/AndroidRuntime(1262): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:50:24.814: E/AndroidRuntime(1262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:50:24.814: E/AndroidRuntime(1262): ... 11 more
04-23 05:53:39.893: E/Trace(1352): error opening trace file: No such file or directory (2)
04-23 05:53:40.044: D/AndroidRuntime(1352): Shutting down VM
04-23 05:53:40.044: W/dalvikvm(1352): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:53:40.063: E/AndroidRuntime(1352): FATAL EXCEPTION: main
04-23 05:53:40.063: E/AndroidRuntime(1352): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.os.Looper.loop(Looper.java:137)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:53:40.063: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:53:40.063: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:53:40.063: E/AndroidRuntime(1352): at dalvik.system.NativeStart.main(Native Method)
04-23 05:53:40.063: E/AndroidRuntime(1352): Caused by: java.lang.NullPointerException
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:53:40.063: E/AndroidRuntime(1352): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:17)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:53:40.063: E/AndroidRuntime(1352): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:53:40.063: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:53:40.063: E/AndroidRuntime(1352): ... 11 more
04-23 05:53:40.106: I/Process(1352): Sending signal. PID: 1352 SIG: 9
04-23 05:57:17.853: D/AndroidRuntime(1452): Shutting down VM
04-23 05:57:17.853: W/dalvikvm(1452): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 05:57:17.873: E/AndroidRuntime(1452): FATAL EXCEPTION: main
04-23 05:57:17.873: E/AndroidRuntime(1452): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ptx.calcplus/com.ptx.calcplus.MainActivity}: java.lang.NullPointerException
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.os.Looper.loop(Looper.java:137)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 05:57:17.873: E/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 05:57:17.873: E/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 05:57:17.873: E/AndroidRuntime(1452): at dalvik.system.NativeStart.main(Native Method)
04-23 05:57:17.873: E/AndroidRuntime(1452): Caused by: java.lang.NullPointerException
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:360)
04-23 05:57:17.873: E/AndroidRuntime(1452): at com.ptx.calcplus.MainActivity.<init>(MainActivity.java:18)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.Class.newInstanceImpl(Native Method)
04-23 05:57:17.873: E/AndroidRuntime(1452): at java.lang.Class.newInstance(Class.java:1319)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-23 05:57:17.873: E/AndroidRuntime(1452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-23 05:57:17.873: E/AndroidRuntime(1452): ... 11 more
Click to expand...
Click to collapse
[==)BULLET(==] said:
Please put those Log.i(String String); in my code where ever it is appropriate.
Here is the whole logcat. Please help!
Click to expand...
Click to collapse
They are not needed. I just wanted to show you how to get the log.
I will check the code later on my computer.
Thanks for the log.
---------- Post added at 03:04 PM ---------- Previous post was at 02:10 PM ----------
[==)BULLET(==] said:
Works perfectly thank you.
Just tried to add dialog and clear, exit buttons but getting fc again. Please look into . I am really excited to make my first app.
Thank you once again
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a-b;
txtAn.setText(""+c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a*b;
txtAn.setText(""+c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
if(txtN1.getText().toString().isEmpty()||txtN2.getText().toString().isEmpty()){
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else if(b==0)
{
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {}});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else{
c=a+b;
txtAn.setText(""+c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
[user=439709]@override[/user]
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;
}
}
Please help me out!
Click to expand...
Click to collapse
It is a similar mistake. You cannot do anything related with Android views in your field declarations.
You need to do it in your onCreate method, if you load the layout from a xml, after the setContentView method. So change it to this:
MainActivity.java
Code:
package com.ptx.calcplus;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert;
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Add = (Button) findViewById(R.id.btnAdd);
... //your other stuff
dlgAlert = new AlertDialog.Builder(this);
...
This should work. Try it.
You're targetting min sdk of 8, which doesn't allow checking if string ".isEmpty()", which IF I'M NOT WRONG, is not included in older version of Android due to different version of Java. So I've changed it to check if the length is less than 0 before calculating.
Code:
.length() < 1
Secondly, you're converting the values of the Textbox BEFORE you check if the input is empty or not. Check before converting. Because if your input is empty, it is unable to convert a NULL into a double.
Lastly, one small error. Your DIVIDE is still PLUS. I've corrected it for you.
Sorry for the late reply! Hope there ain't any error.
Oh, one small tip. Try reading up "Try and Catch" for Android. Good for preventing force closing of apps.
Code:
package com.example.caltest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert;
double a = 0, b = 0, c = 0;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dlgAlert = new AlertDialog.Builder(MainActivity.this);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a + b;
txtAn.setText("" + c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a - b;
txtAn.setText("" + c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a * b;
txtAn.setText("" + c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else if (b == 0) {
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a/b;
txtAn.setText("" + c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
finish();
}
});
}
[user=439709]@override[/user]
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;
}
}
@nikwen @frenzyboi
Thank you to both of you from the bottom of my heart.
Really feeling awesome after seeing my first app running and rocking.
Any tips for what to do next?
Once again thank you to both of you!!
Sincere Regards
Bullet
[==)BULLET(==] said:
@nikwen @frenzyboi
Thank you both of you from the bottom of my heart.
Real feeling awesome after seeing my first app running and rocking.
Any tips for what to do next?
Once again thank you to both of you!!
Sincere Regards
Bullet
Click to expand...
Click to collapse
You are welcome.
My tips (because you asked me ):
I have started many projects and finished few of them.
The point is: Make an app you NEED or one you think of "That would be VERY cool".
The ones I have needed have always been the ones I have finished.
Good luck.
(Maybe consider creating a game or build an app that does annoying things automatically which you normally have to do yourself.)
nikwen said:
You are welcome.
My tips (because you asked me ):
I have started many projects and finished few of them.
The point is: Make an app you NEED or one you think of "That would be VERY cool".
The ones I have needed have always been the ones I have finished.
Good luck.
(Maybe consider creating a game or build an app that does annoying things automatically which you normally have to do yourself.)
Click to expand...
Click to collapse
I agree with nikwen. The apps you use will be the apps you finish. My advice to you would be to start your calculator over. Try to do it from start to finish and add features or improve on ones you currently have. For instance, add a feature that logs your input and calculation similar to the calculators that print on what they are doing on paper. Once you get the basics down, then you should move on to something more advanced.
Learn and love your logcats. It will help you so much in the debug process.

[Q] What is wrong with my project?

Hi all, I'm fairly new to Java and my overall coding skills are not as advanced as I'd like them to be but I really would appreciate it if someone could help me with this problem.
My first goal is to code an application for Android which measures the acceleration (X, Y, Z directions) and displays the values in a TextView.
There will be other user configurable options like unit conversion or limits with audio warnings etc. later on.
Right now I only have a few lines of code and the application already force closes right after starting.
I am posting my MainActivity.java, my activity_main.xml and the sensoractivity2 Manifest. Please point me in the right direction!
MainActivity.java:
Code:
package com.example.sensoractivity2;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
}
public void onSensorChanged(SensorEvent event) {
float x, y, z = 0;
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
x=event.values[0];
y=event.values[1];
z=event.values[2];
TextView tx = (TextView) findViewById(R.id.textView1);
tx.setText((int) x);
TextView ty = (TextView) findViewById(R.id.textView2);
ty.setText((int) y);
TextView tz = (TextView) findViewById(R.id.textView3);
tz.setText((int) z);
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
}
activity_main.xml
Code:
<?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" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="X-Wert" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Y-Wert" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Z-Wert" />
</LinearLayout>
sensoractivity2 Manifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sensoractivity2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name="com.example.sensoractivity2.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
First thing I see is that you are not setting your view in your activity classes "oncreate" method. Can you post your logcat output when the app force closes? That will help the most.
Could you please post a logcat?
Just the lines of your app. Get it using the logcat view in Eclipse.
Look at the bold for changes that will help you. When you are working with view objects, you shouldn't create the object in a listener or something that is called over and over. You will be creating a memory leak.
Code:
package com.example.sensoractivity2;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
[B]TextView tx = null;
TextView ty = null;
TextView tz = null;[/B]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
[B] setContentView(R.layout.activity_main);[/B]
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
[B]tx = (TextView) findViewById(R.id.textView1);
ty = (TextView) findViewById(R.id.textView2);
tz = (TextView) findViewById(R.id.textView3);[/B]
}
public void onSensorChanged(SensorEvent event) {
float x, y, z = 0;
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
x=event.values[0];
y=event.values[1];
z=event.values[2];
[B]tx.setText((int) x);
ty.setText((int) y);
tz.setText((int) z);[/B]
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
}
Here is the part of the catlog which I believe to be relevant when the crash occurs:
Code:
04-28 18:34:24.628: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
04-28 18:34:25.750: E/Trace(1735): error opening trace file: No such file or directory (2)
04-28 18:34:27.452: I/ARMAssembler(36): generated scanline__00000077:03515104_00009002_00000000 [127 ipp] (149 ins) at [0x40f081f0:0x40f08444] in 34521256 ns
04-28 18:34:29.430: I/Choreographer(1153): Skipped 388 frames! The application may be doing too much work on its main thread.
04-28 18:34:29.462: I/ARMAssembler(36): generated scanline__00000077:03010104_00008002_00000000 [ 89 ipp] (110 ins) at [0x40f08450:0x40f08608] in 17654283 ns
04-28 18:34:30.825: W/ActivityManager(1003): Launch timeout has expired, giving up wake lock!
04-28 18:34:31.673: D/AndroidRuntime(1735): Shutting down VM
04-28 18:34:31.673: W/dalvikvm(1735): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-28 18:34:31.737: E/AndroidRuntime(1735): FATAL EXCEPTION: main
04-28 18:34:31.737: E/AndroidRuntime(1735): java.lang.NullPointerException
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:27)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Looper.loop(Looper.java:137)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 18:34:31.737: E/AndroidRuntime(1735): at dalvik.system.NativeStart.main(Native Method)
04-28 18:34:31.813: W/ActivityManager(1003): Force finishing activity com.example.sensoractivity2/.MainActivity
04-28 18:34:31.893: W/WindowManager(1003): Failure taking screenshot for (328x583) to layer 21010
04-28 18:34:32.643: D/dalvikvm(1003): GC_FOR_ALLOC freed 588K, 26% free 7082K/9496K, paused 471ms, total 481ms
Thanks for your hints, zalez! Going to try that now.
The logcat states a nullpointer error. I believe my corrections will fix at least that error.
spelaben said:
Here is the part of the catlog which I believe to be relevant when the crash occurs:
Code:
04-28 18:34:24.628: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
04-28 18:34:25.750: E/Trace(1735): error opening trace file: No such file or directory (2)
04-28 18:34:27.452: I/ARMAssembler(36): generated scanline__00000077:03515104_00009002_00000000 [127 ipp] (149 ins) at [0x40f081f0:0x40f08444] in 34521256 ns
04-28 18:34:29.430: I/Choreographer(1153): Skipped 388 frames! The application may be doing too much work on its main thread.
04-28 18:34:29.462: I/ARMAssembler(36): generated scanline__00000077:03010104_00008002_00000000 [ 89 ipp] (110 ins) at [0x40f08450:0x40f08608] in 17654283 ns
04-28 18:34:30.825: W/ActivityManager(1003): Launch timeout has expired, giving up wake lock!
04-28 18:34:31.673: D/AndroidRuntime(1735): Shutting down VM
04-28 18:34:31.673: W/dalvikvm(1735): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-28 18:34:31.737: E/AndroidRuntime(1735): FATAL EXCEPTION: main
04-28 18:34:31.737: E/AndroidRuntime(1735): java.lang.NullPointerException
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:27)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Looper.loop(Looper.java:137)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 18:34:31.737: E/AndroidRuntime(1735): at dalvik.system.NativeStart.main(Native Method)
04-28 18:34:31.813: W/ActivityManager(1003): Force finishing activity com.example.sensoractivity2/.MainActivity
04-28 18:34:31.893: W/WindowManager(1003): Failure taking screenshot for (328x583) to layer 21010
04-28 18:34:32.643: D/dalvikvm(1003): GC_FOR_ALLOC freed 588K, 26% free 7082K/9496K, paused 471ms, total 481ms
Thanks for your hints, zalez! Going to try that now.
Click to expand...
Click to collapse
zalez said:
The logcat states a nullpointer error. I believe my corrections will fix at least that error.
Click to expand...
Click to collapse
True, nullpointer errors are fixed. After debugging it again, I'm getting these errors now:
Code:
04-28 19:07:59.466: E/AndroidRuntime(858): FATAL EXCEPTION: main
04-28 19:07:59.466: E/AndroidRuntime(858): android.content.res.Resources$NotFoundException: String resource ID #0x0
04-28 19:07:59.466: E/AndroidRuntime(858): at android.content.res.Resources.getText(Resources.java:230)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.widget.TextView.setText(TextView.java:3769)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:33)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Looper.loop(Looper.java:137)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 19:07:59.466: E/AndroidRuntime(858): at dalvik.system.NativeStart.main(Native Method)
Any ideas?
spelaben said:
True, nullpointer errors are fixed. After debugging it again, I'm getting these errors now:
Code:
04-28 19:07:59.466: E/AndroidRuntime(858): FATAL EXCEPTION: main
04-28 19:07:59.466: E/AndroidRuntime(858): android.content.res.Resources$NotFoundException: String resource ID #0x0
04-28 19:07:59.466: E/AndroidRuntime(858): at android.content.res.Resources.getText(Resources.java:230)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.widget.TextView.setText(TextView.java:3769)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:33)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Looper.loop(Looper.java:137)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 19:07:59.466: E/AndroidRuntime(858): at dalvik.system.NativeStart.main(Native Method)
Any ideas?
Click to expand...
Click to collapse
It needs to be
Code:
tx.setText(String.valueOf(x));
ty.setText(String.valueOf(y));
tz.setText(String.valueOf(z));
If you pass an int, the TextView thinks that it is a resource id. That is why you need to convert it to a String first.
I over looked the bold part. When setting text for a Textview, it has to be in string format. There is no implied conversion.
Code:
package com.example.sensoractivity2;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
TextView tx = null;
TextView ty = null;
TextView tz = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
setContentView(R.layout.activity_main);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
tx = (TextView) findViewById(R.id.textView1);
ty = (TextView) findViewById(R.id.textView2);
tz = (TextView) findViewById(R.id.textView3);
}
public void onSensorChanged(SensorEvent event) {
float x, y, z = 0;
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
x=event.values[0];
y=event.values[1];
z=event.values[2];
tx.setText[B](Integer.toString(x)[/B]);
ty.setText([B]Integer.toString(y)[/B]);
tz.setText([B]Integer.toString(z)[/B]);
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
}
nikwen said:
It needs to be
Code:
tx.setText(String.valueOf(x));
ty.setText(String.valueOf(y));
tz.setText(String.valueOf(z));
If you pass an int, the TextView thinks that it is a resource id. That is why you need to convert it to a String first.
Click to expand...
Click to collapse
Yes! That did the trick! Now my next problem is that I only see one value instead of three, from there on I will try to move on by myself.
Sorry, I'm not sure if this is relevant, but you aren't overriding your onCreate method? Could that have anything to do with it?
MaartenXDA said:
Sorry, I'm not sure if this is relevant, but you aren't overriding your onCreate method? Could that have anything to do with it?
Click to expand...
Click to collapse
He does:
public void onCreate(Bundle savedInstanceState) {
Click to expand...
Click to collapse
He just did not wrote the @override annotation before that. As far as i know, you do not have to use it.
EDIT: Yep, it does not matter. See this: http://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why
It says that it is just for ensuring that you are overriding the right method and for making the code easier to read.
Hi all, I am a bit further with my project since I found some time to work on it again.
//edit, force closes on starting fixed!
Here is what it is supposed to be doing: It reads the x, y and z values for acceleration from the LINEAR_ACCELERATION sensor. If a certain value is exceeded a timer will be started. If the amount of seconds the timer counts is higher than a defined threshold, it will play the default notifcation sound.
If the value from the sensor is below the threshold, it will stop the timer. The whole timer thing isn't working, the notification is played as soon as the normal acceleration threshold is passed and the time is ignored.
Please review my code below and tell me what I'm not seeing here, note that I'm still a noob.
Also I'm interested in a method to capture the maximum values read from the sensor and put it in a textview, can you help me?
AccelMeter.java:
Code:
package com.example.accelmeter;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class AccelMeter extends Activity implements SensorEventListener {
private SensorManager sensorManager;
// Objekte deklarieren
TextView xC;
TextView yC;
TextView zC;
Chronometer chrono;
/* accThreshold = Schwellenwert in m/s² für die Beschleunigung
* accInterval = Zeitraum in Sekunden, über den der Wert für die Beschleunigung überwacht wird
*/
private float accThreshold = 50;
private float accInterval = 0;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accel_meter);
// Achsen Objekte erstellen
xC=(TextView)findViewById(R.id.xCoordinate);
yC=(TextView)findViewById(R.id.yCoordinate);
zC=(TextView)findViewById(R.id.zCoordinate);
/* Sensor.TYPE_LINEAR_ACCELERATION = Beschleunigung auf jeder Achse ohne Gravitation in m/s²
* SENSOR_DELAY_FASTEST = schnellster Modus für Messung. Alternativen z.B. _GAME, _NORMAL oder _UI
*/
sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
SensorManager.SENSOR_DELAY_NORMAL);
// Schwellenwert festlegen und mit einer Toast-Benachrichtigung bestätigen, Fehlerbehandlung wenn kein Wert eingegeben wurde
Button setThreshold = (Button)findViewById(R.id.setThreshold);
setThreshold.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
EditText et = (EditText)findViewById(R.id.threshold);
accThreshold = Float.valueOf(et.getText().toString());
Toast.makeText(getApplicationContext(), "Neuer Schwellenwert festgelegt!", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Es wurde noch kein Wert eingegeben!", Toast.LENGTH_SHORT).show();
}
}
});
// Intervall festlegen und mit einer Toast-Benachrichtigung bestätigen, Fehlerbehandlung wenn kein Wert eingegeben wurde
Button setInterval = (Button)findViewById(R.id.setInterval);
setInterval.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
EditText et = (EditText)findViewById(R.id.editInterval);
accInterval = Float.valueOf(et.getText().toString());
Toast.makeText(getApplicationContext(), "Neues Intervall festgelegt!", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Es wurde noch kein Wert eingegeben!", Toast.LENGTH_SHORT).show();
}
}
});
// Programm beenden
Button exit = (Button)findViewById(R.id.exit);
exit.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
public void onSensorChanged(SensorEvent event){
// Sensor Typ überprüfen
if(event.sensor.getType()==Sensor.TYPE_LINEAR_ACCELERATION){
// Richtungen verknüpfen
float x=event.values[0];
float y=event.values[1];
float z=event.values[2];
// Gerundete Ergebnisse mit vier Nachkommastellen ausgeben
xC.setText("X: "+(Math.abs(Math.round(x * 1000) / 1000.0)));
yC.setText("Y: "+(Math.abs(Math.round(y * 1000) / 1000.0)));
zC.setText("Z: "+(Math.abs(Math.round(z * 1000) / 1000.0)));
// Wenn Beschleunigung über Schwellenwert liegt, starte Timer. Wenn Timer das festgelete Intervall überschreitet, spiele Benachrichtigungston
if (x + y + z > accThreshold)
{
chrono = new Chronometer(this);
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
long seconds = ((chrono.getBase()-SystemClock.elapsedRealtime()/1000%60));
if (seconds >= accInterval)
{
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
}
else
{
chrono.stop();
}
}
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
}
activity_accel_meter.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow tools:ignore="ExtraText" >
<TextView
android:id="@+id/xCoordinate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X Koordinate: "
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/yCoordinate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Y Koordinate: "
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/zCoordinate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Z Koordinate: "
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
/>
</TableRow>
<EditText
android:id="@+id/threshold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Schwellenwert (float)"
android:inputType="numberDecimal"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/setThreshold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schwellenwert festlegen"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/editInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Zeit in Sekunden"
android:inputType="number"
tools:ignore="HardcodedText" >
<requestFocus />
</EditText>
<Button
android:id="@+id/setInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zeitraum für Überwachung festlegen"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beenden"
tools:ignore="HardcodedText" />
</TableLayout>
Yay German code (live there, too) xD Initialise your seconds in your onCreate, it's much nicer and probably the problem. A method gets the highest value the sensor measured would be a simple
Code:
double savedVal=0; //or any other type
private void updateMaxVal(){
double currentVal =// get the value from the specific sensor
if(savedVal<currentVal) {
savedVal = currentVal;
// maybe save the time as well
}
You'd have to put that method in the onsensorchanged so it will be called often. Then update your text View with the new saved value
SimplicityApks said:
Yay German code (live there, too) xD Initialise your seconds in your onCreate, it's much nicer and probably the problem. A method gets the highest value the sensor measured would be a simple
Code:
double savedVal=0; //or any other type
private void updateMaxVal(){
double currentVal =// get the value from the specific sensor
if(savedVal<currentVal) {
savedVal = currentVal;
// maybe save the time as well
}
You'd have to put that method in the onsensorchanged so it will be called often. Then update your text View with the new saved value
Click to expand...
Click to collapse
Hey fellow German!
If I initialise the seconds variable in the onCreate part it says that the variable is not being used (yellow marking) and in the code below I get an error obviously stating that the variable is unknown. ^^
I have three different values, how can I link the x, y and z variables in the method and how can I make sure the variables are known inside of the method? (Same problem as above)
Since I don't know how to do it with a method I just wrote the following code in my onsensorchanged part, the problem is that the max value textviews always show the same as the current value textviews:
float savedValX = 0;
float savedValY = 0;
float savedValZ = 0;
float currentValX = event.values[0];
float currentValY = event.values[1];
float currentValZ = event.values[2];
if (savedValX < currentValX) {
savedValX = currentValX;
xM.setText("X max: "+(Math.abs(Math.round(currentValX * 1000) / 1000.0)));
}
if (savedValY < currentValY) {
savedValY = currentValY;
yM.setText("Y max: "+(Math.abs(Math.round(currentValY * 1000) / 1000.0)));
}
if (savedValZ < currentValZ) {
savedValZ = currentValZ;
zM.setText("Z max: "+(Math.abs(Math.round(currentValZ * 1000) / 1000.0)));
}
Also I still have the problem that my seconds interval is being ignored.
//edit, fixed it! Now I only need the max value method.
OK so I now understand what you are trying to do with your Chronometer, the problem is that you reinitialize it every time the onSensorChanged is called so if you then ask for the seconds it has just started. To fix this, you could set an onChronometerTickListener and set your textViews in that method. To avoid recreating the Chrono use
Code:
if(chrono==null){
chrono = new Chronometer();
chrono.start();
}
If u don't want the tick listener or it doesn't work ( haven't used it yet) you can put your if(seconds<...)in the else {}of above method. But remember that the onSensorChanged is called EVERYTIME the sensor registers a change, this might be very often or just sometimes, so there is no guarantee that the text views will be updated if the else clause in that method is used
PS forget about the initializing of the seconds, I don't know what I was thinking yesterday, but I guess it was too late ...
/*edit:
What I meant with
Code:
double savedVal=0; //or any other type
private void updateMaxVal(){
is that you save your value in your class ("globally"), so that it is accessible to the whole class.
and to do it nicely you can do it like this:
Code:
float savedValX = 0;
float savedValY = 0;
float savedValZ = 0;
boolean change = false;
private void updateMaxVals(SensorEvent event){ // call this method in your onSensorChanged
change = false;
savedValX = getMax(event.values[0], savedValX);
if(change){
xM.setText("X max: "+(Math.abs(Math.round(savedValX * 1000) / 1000.0)));
}
savedValY = getMax(event.values[1], savedValY);
if(change){
yM.setText("Y max: "+(Math.abs(Math.round(savedValY * 1000) / 1000.0)));
}
savedValZ = getMax(event.values[2], savedValZ);
if(change){
yM.setText("Z max: "+(Math.abs(Math.round(savedValZ * 1000) / 1000.0)));
}
}
private float getMax(float currentVal, float savedVal){
if(currentVal > savedVal){
change = true;
return currentVal;
}else{
change = false;
return savedVal;
}
}

NullPointerException at findPreference

I'm creating a new FragmentPreference and then I want add a OnClickListener to an Preference:
My PreferenceFragment-Class:
Code:
public class PreferencesFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
And my FragmentActivity:
Code:
public class SettingsActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferencesFragment frag = new PreferencesFragment();
getFragmentManager().beginTransaction().replace(android.R.id.content, frag).commit();
Preference deleteLocalDataPref = frag.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
}
OnPreferenceClickListener Pref_OnClickhandler = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
new DeleteSettings().execute();
return false;
}
};
}
And the error:
02-10 08:06:10.598: E/AndroidRuntime(1836): FATAL EXCEPTION: main
02-10 08:06:10.598: E/AndroidRuntime(1836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.SettingsActivity}: java.lang.NullPointerException
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.os.Looper.loop(Looper.java:137)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-10 08:06:10.598: E/AndroidRuntime(1836): at java.lang.reflect.Method.invokeNative(Native Method)
02-10 08:06:10.598: E/AndroidRuntime(1836): at java.lang.reflect.Method.invoke(Method.java:511)
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-10 08:06:10.598: E/AndroidRuntime(1836): at dalvik.system.NativeStart.main(Native Method)
02-10 08:06:10.598: E/AndroidRuntime(1836): Caused by: java.lang.NullPointerException
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.test.SettingsActivity.onCreate(SettingsActivity.java:44)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.Activity.performCreate(Activity.java:5104)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-10 08:06:10.598: E/AndroidRuntime(1836): ... 11 more
Click to expand...
Click to collapse
Why I get a NullPointerException? The Preference does exist...
Code:
<Preference
android:key="deleteLocalData"
android:summary="@string/pref_delete_local_data_summary"
android:title="@string/pref_delete_local_data" />
What happens when you comment the line you think is offending? And which line are you commenting?
Please give a thanks if you think this post helped you!
Sent from my Nexus 4 using XDA Premium 4 Mobile App .
When I comment the lines
Code:
Preference deleteLocalDataPref = frag.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
my preferences are shown correctly.
OK, I changed some parts. This is what works for me:
Code:
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
public class SettingsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
PreferenceFragment preferenceFragment = (PreferenceFragment) getFragmentManager().findFragmentById(R.id.pref_frag_id);
Preference deleteLocalDataPref = preferenceFragment.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
}
Preference.OnPreferenceClickListener Pref_OnClickhandler = new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
new DeleteSettings().execute();
return false;
}
};
}
/res/layout/settings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.example.app.PreferencesFragment"
android:id="@+id/pref_frag_id"/>
</FrameLayout>
(Replace the package name.)
/res/xml/settings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:key="deleteLocalData"
android:summary="@string/pref_delete_local_data_summary"
android:title="@string/pref_delete_local_data" />
</PreferenceScreen>
I changed the way the Fragment is added. If you need to do it dynamically, have a look at a tutorial again and follow it closely.
You don't need to use a PreferenceActivity. The PreferenceFragment kind of replaced it. It is more flexible (it can be added to any kind of Activity) and the PreferenceActivity should only be used for apps which are supposed to work on Android versions below 3.0.

[Q] Problem with simple android app with VideoView?

Hello,
I am trying to build an Android Studio project based on a simple example from the web with VideoView. Everything seems OK, the project builds successfully but both in the emulator and on my device it gives an error: "Unfortunately [myapp] has stopped". This is getting really frustrating, I've searched the Internet for similar errors but didn't find any solution to my case. I think the code is ok but there is something with the settings because I imported the project from a web example:
itcuties[dot]com/android/play-video/
Anyway, the code is:
........SelectActivity.java........
Code:
package com.itcuties.android.videoplayer;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* Select video source activity.
*
* @see ITCuties
*/
public class SelectActivity extends Activity implements OnClickListener {
private Button playFromUrlButton;
private Button playOnYouTubeButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select);
playFromUrlButton = (Button) findViewById(R.id.buttonURL);
playOnYouTubeButton = (Button) findViewById(R.id.buttonOnYouTube);
// Set onClickListener
playFromUrlButton.setOnClickListener(this);
playOnYouTubeButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// Check which button was clicked
if (playFromUrlButton.isPressed()) {
Intent i = new Intent(SelectActivity.this, URLVideoActivity.class);
SelectActivity.this.startActivity(i);
} else if (playOnYouTubeButton.isPressed()) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse([B][I]"<Youtbe page>[/I][/B]"));
SelectActivity.this.startActivity(i);
}
}
}
........URLVideoActivity.java........
Code:
package com.itcuties.android.videoplayer;
import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;
/**
* Play Video from URL
*
* @see ITCuties
*/
public class URLVideoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.url_activity_video);
VideoView video = (VideoView)findViewById(R.id.videoView);
video.setVideoPath("[I][B]<Address to mp4 file>[/B][/I]");
video.start();
}
}
........AndroidManifest.xml........
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[I][B]<schemas android link>[/B][/I]"
package="com.itcuties.android.videoplayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.itcuties.android.videoplayer.URLVideoActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.itcuties.android.videoplayer.SelectActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_select">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The error from emulator console:
Code:
07-02 17:41:19.689 2524-2524/? D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
07-02 17:41:20.270 2524-2524/? I/dalvikvm﹕ Turning on JNI app bug workarounds for target SDK version 8...
07-02 17:41:20.479 2524-2524/? E/Trace﹕ error opening trace file: No such file or directory (2)
07-02 17:41:20.939 2524-2524/com.itcuties.android.videoplayer D/AndroidRuntime﹕ Shutting down VM
07-02 17:41:20.939 2524-2524/com.itcuties.android.videoplayer W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-02 17:41:20.959 2524-2524/com.itcuties.android.videoplayer E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.itcuties.android.videoplayer/com.itcuties.android.videoplayer.SelectActivity}: java.lang.ClassNotFoundException: Didn't find class "com.itcuties.android.videoplayer.SelectActivity" on path: /data/app/com.itcuties.android.videoplayer-2.apk
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.itcuties.android.videoplayer.SelectActivity" on path: /data/app/com.itcuties.android.videoplayer-2.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Anybody? Thanks in advance.
Adi.
Classnotfound exception
You didn't post the SelectActivity.java for this.
Did you create this ?
Please share the content for the SelectActivity.java class.
Change the below codes :
Code:
if (playFromUrlButton.isPressed()) {
Intent i = new Intent(SelectActivity.this, URLVideoActivity.class);
SelectActivity.this.startActivity(i);
} else if (playOnYouTubeButton.isPressed()) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse([B][I]"<Youtbe page>[/I][/B]"));
SelectActivity.this.startActivity(i);
}
To this:
Code:
if (playFromUrlButton.isPressed()) {
Intent i = new Intent(SelectActivity.this, URLVideoActivity.class);
startActivity(i);
} else if (playOnYouTubeButton.isPressed()) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse([B][I]"<Youtbe page>[/I][/B]"));
startActivity(i);
}
satyampv,
I guess I have? I don't understand.
Vivek_Neel:
Thanks for reply but the error sill persists
haloperidollly said:
satyampv,
I guess I have? I don't understand.
Vivek_Neel:
Thanks for reply but the error sill persists
Click to expand...
Click to collapse
Can you try to run this app on your phone and see if it works?
It doesn't work neither on emulator nor on my tablet - same error.

[Q]Parcelable Object return BadParcelableException: ClassNotFoundException

I have a problem when I write pracelable object and receive from another application that I wrote. Everytime when I tried to get the object it always turned out to be BadParcelableException: ClassNotFoundException when unmarshalling.
I've been looking around and wonder if it turned out bad when I send to another application. Or it's simply I had error in my codes.
Please tell me where did I go wrong.
Note: please understand that I have been looking for answer for this for a while and I still can't find where is my problem is. I looked up many people's code and tested out many times but still can't get my app right. So that is why I am here to ask help. If some people still think I am a lazy noob, I guess I am too lazy for some people to draw that conclusion. I should reconsider of my action again.
My situation is:
I wrote 2 apps and one is sending a parcelable object to another application. First app it's working correctly to send the object to another. However, as the second app receive it, it goes wrong and gives out the BadParcelableException as I run the process. I am not using bundle because I saw many examples that it is not necessary to do so. If I have been wrong please correct me. Both app contains the ParcelableObject class.
Send object lines:
Code:
Intent intent = new Intent();
ParcelableObjectmyObject = newParcelableObject();
myObject = newParcelableObject(result_name, resut_lv, result_race,
result_job, result_nation, result_guild, result_mission);
intent.putExtra("ACTION_DATA_TRANSFER",myObject);
intent.setClassName(target_app, target_app+".ReceiveMain");
startActivity(intent);
First app Manifest:
Code:
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="abc.com.android.send_app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SendMain"
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>
Receive Lines at second app:
Code:
ParcelableObjectmyObject = newParcelableObject();
myObject = getIntent().getParcelableExtra("ACTION_DATA_TRANSFER");//always crashed at this line
if(getIntent().hasExtra("ACTION_DATA_TRANSFER")){
Log.w("****CHECKING****",myObject.getName());
item1.setText("The Character's name is: "+myObject.getName());
}else{
Toast.makeText(getApplicationContext(),"There is not data passed yet",
Toast.LENGTH_LONG).show();
}
Second app Manifest:
Code:
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="def.com.android.receive_app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ReceiveMain"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my ParcelableObject class that implements Parcelable:
Code:
private String name;
private int lv;
private String race;
private String job;
private String nation;
private String guild;
public String mission;
public void setName(String name) {
this.name = name;
}
public void setLv(int lv) {
this.lv = lv;
}
public void setRace(String race) {
this.race = race;
}
public void setJob(String job) {
this.job = job;
}
public void setNation(String nation) {
this.nation = nation;
}
public void setGuild(String guild) {
this.guild = guild;
}
public void setMission(String mission) {
this.mission = mission;
}
public ParcelableObject(String name, int lv, String race, String job, String
nation, String guild, String mission) {
// TODO Auto-generated constructor stub
this.name = name;
this.lv = lv;
this.race = race;
this.job = job;
this.nation = nation;
this.guild = guild;
this.mission = mission;
}
public String getName() {
return name;
}
public int getLv() {
return lv;
}
public String getRace() {
return race;
}
public String getJob() {
return job;
}
public String getNation() {
return nation;
}
public String getGuild() {
return guild;
}
public String getMission() {
return mission;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
Log.w("****PO CHECKING****", "describeContents called");
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
Log.w("****PO CHECKING****", "writeToParcel called");
dest.writeString(name);
dest.writeString(job);
dest.writeInt(lv);
dest.writeString(race);
dest.writeString(guild);
dest.writeString(nation);
dest.writeString(mission);
}
public ParcelableObject() {
// TODO Auto-generated constructor stub
super();
Log.i("**check if exist**", "start parcel");
}
public static final Parcelable.Creator<ParcelableObject> CREATOR =
new Parcelable.Creator<ParcelableObject>() {
@Override
public ParcelableObject createFromParcel(Parcel in) {
// TODO Auto-generated method stub
Log.w("checking out", "createFromParcel");
pObject.name = in.readString();
pObject.job = in.readString();
pObject.lv = in.readInt();
pObject.race = in.readString();
pObject.guild = in.readString();
pObject.nation = in.readString();
pObject.mission = in.readString();
return pObject;
}
@Override
public ParcelableObject[] newArray(int size) {
// TODO Auto-generated method stub
return new ParcelableObject[size];
}
};
Error Log:
Code:
11-18 09:52:39.444: E/Parcel(29463): Class not found when unmarshalling: abc.com.android.send_app.ParcelableObject
11-18 09:52:39.444: E/Parcel(29463): java.lang.ClassNotFoundException: abc.com.android.send_app.ParcelableObject
11-18 09:52:39.444: E/Parcel(29463): at java.lang.Class.classForName(Native Method)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.Class.forName(Class.java:251)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readParcelable(Parcel.java:2097)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readValue(Parcel.java:2013)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Bundle.unparcel(Bundle.java:249)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Bundle.getParcelable(Bundle.java:1206)
11-18 09:52:39.444: E/Parcel(29463): at android.content.Intent.getParcelableExtra(Intent.java:4652)
11-18 09:52:39.444: E/Parcel(29463): at def.com.android.receive_app.ReceiveMain.onCreate(ReceiveMain.java:23)
11-18 09:52:39.444: E/Parcel(29463): at android.app.Activity.performCreate(Activity.java:5231)
11-18 09:52:39.444: E/Parcel(29463): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Handler.dispatchMessage(Handler.java:102)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Looper.loop(Looper.java:136)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.main(ActivityThread.java:5001)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.reflect.Method.invokeNative(Native Method)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.reflect.Method.invoke(Method.java:515)
11-18 09:52:39.444: E/Parcel(29463): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-18 09:52:39.444: E/Parcel(29463): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-18 09:52:39.444: E/Parcel(29463): at dalvik.system.NativeStart.main(Native Method)
11-18 09:52:39.444: E/Parcel(29463): Caused by: java.lang.NoClassDefFoundError: abc/com/android/send_app/ParcelableObject
11-18 09:52:39.444: E/Parcel(29463): ... 24 more
11-18 09:52:39.444: E/Parcel(29463): Caused by: java.lang.ClassNotFoundException: Didn't find class "abc.com.android.send_app.ParcelableObject" on path: DexPathList[[zip file "/data/app/def.com.android.receive_app-2.apk"],nativeLibraryDirectories=[/data/app-lib/def.com.android.receive_app-2, /vendor/lib, /system/lib]]
11-18 09:52:39.444: E/Parcel(29463): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-18 09:52:39.444: E/Parcel(29463): ... 24 more
LadyChocobo said:
I have a problem when I write pracelable object and receive from another application that I wrote. Everytime when I tried to get the object it always turned out to be BadParcelableException: ClassNotFoundException when unmarshalling.
I've been looking around and wonder if it turned out bad when I send to another application. Or it's simply I had error in my codes.
Please tell me where did I go wrong.
Note: please understand that I have been looking for answer for this for a while and I still can't find where is my problem is. I looked up many people's code and tested out many times but still can't get my app right. So that is why I am here to ask help. If some people still think I am a lazy noob, I guess I am too lazy for some people to draw that conclusion. I should reconsider of my action again.
My situation is:
I wrote 2 apps and one is sending a parcelable object to another application. First app it's working correctly to send the object to another. However, as the second app receive it, it goes wrong and gives out the BadParcelableException as I run the process. I am not using bundle because I saw many examples that it is not necessary to do so. If I have been wrong please correct me. Both app contains the ParcelableObject class.
Send object lines:
Code:
Intent intent = new Intent();
ParcelableObjectmyObject = newParcelableObject();
myObject = newParcelableObject(result_name, resut_lv, result_race,
result_job, result_nation, result_guild, result_mission);
intent.putExtra("ACTION_DATA_TRANSFER",myObject);
intent.setClassName(target_app, target_app+".ReceiveMain");
startActivity(intent);
First app Manifest:
Code:
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="abc.com.android.send_app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SendMain"
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>
Receive Lines at second app:
Code:
ParcelableObjectmyObject = newParcelableObject();
myObject = getIntent().getParcelableExtra("ACTION_DATA_TRANSFER");//always crashed at this line
if(getIntent().hasExtra("ACTION_DATA_TRANSFER")){
Log.w("****CHECKING****",myObject.getName());
item1.setText("The Character's name is: "+myObject.getName());
}else{
Toast.makeText(getApplicationContext(),"There is not data passed yet",
Toast.LENGTH_LONG).show();
}
Second app Manifest:
Code:
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="def.com.android.receive_app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ReceiveMain"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my ParcelableObject class that implements Parcelable:
Code:
private String name;
private int lv;
private String race;
private String job;
private String nation;
private String guild;
public String mission;
public void setName(String name) {
this.name = name;
}
public void setLv(int lv) {
this.lv = lv;
}
public void setRace(String race) {
this.race = race;
}
public void setJob(String job) {
this.job = job;
}
public void setNation(String nation) {
this.nation = nation;
}
public void setGuild(String guild) {
this.guild = guild;
}
public void setMission(String mission) {
this.mission = mission;
}
public ParcelableObject(String name, int lv, String race, String job, String
nation, String guild, String mission) {
// TODO Auto-generated constructor stub
this.name = name;
this.lv = lv;
this.race = race;
this.job = job;
this.nation = nation;
this.guild = guild;
this.mission = mission;
}
public String getName() {
return name;
}
public int getLv() {
return lv;
}
public String getRace() {
return race;
}
public String getJob() {
return job;
}
public String getNation() {
return nation;
}
public String getGuild() {
return guild;
}
public String getMission() {
return mission;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
Log.w("****PO CHECKING****", "describeContents called");
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
Log.w("****PO CHECKING****", "writeToParcel called");
dest.writeString(name);
dest.writeString(job);
dest.writeInt(lv);
dest.writeString(race);
dest.writeString(guild);
dest.writeString(nation);
dest.writeString(mission);
}
public ParcelableObject() {
// TODO Auto-generated constructor stub
super();
Log.i("**check if exist**", "start parcel");
}
public static final Parcelable.Creator<ParcelableObject> CREATOR =
new Parcelable.Creator<ParcelableObject>() {
@Override
public ParcelableObject createFromParcel(Parcel in) {
// TODO Auto-generated method stub
Log.w("checking out", "createFromParcel");
pObject.name = in.readString();
pObject.job = in.readString();
pObject.lv = in.readInt();
pObject.race = in.readString();
pObject.guild = in.readString();
pObject.nation = in.readString();
pObject.mission = in.readString();
return pObject;
}
@Override
public ParcelableObject[] newArray(int size) {
// TODO Auto-generated method stub
return new ParcelableObject[size];
}
};
Error Log:
Code:
11-18 09:52:39.444: E/Parcel(29463): Class not found when unmarshalling: abc.com.android.send_app.ParcelableObject
11-18 09:52:39.444: E/Parcel(29463): java.lang.ClassNotFoundException: abc.com.android.send_app.ParcelableObject
11-18 09:52:39.444: E/Parcel(29463): at java.lang.Class.classForName(Native Method)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.Class.forName(Class.java:251)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readParcelable(Parcel.java:2097)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readValue(Parcel.java:2013)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Bundle.unparcel(Bundle.java:249)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Bundle.getParcelable(Bundle.java:1206)
11-18 09:52:39.444: E/Parcel(29463): at android.content.Intent.getParcelableExtra(Intent.java:4652)
11-18 09:52:39.444: E/Parcel(29463): at def.com.android.receive_app.ReceiveMain.onCreate(ReceiveMain.java:23)
11-18 09:52:39.444: E/Parcel(29463): at android.app.Activity.performCreate(Activity.java:5231)
11-18 09:52:39.444: E/Parcel(29463): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Handler.dispatchMessage(Handler.java:102)
11-18 09:52:39.444: E/Parcel(29463): at android.os.Looper.loop(Looper.java:136)
11-18 09:52:39.444: E/Parcel(29463): at android.app.ActivityThread.main(ActivityThread.java:5001)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.reflect.Method.invokeNative(Native Method)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.reflect.Method.invoke(Method.java:515)
11-18 09:52:39.444: E/Parcel(29463): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-18 09:52:39.444: E/Parcel(29463): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-18 09:52:39.444: E/Parcel(29463): at dalvik.system.NativeStart.main(Native Method)
11-18 09:52:39.444: E/Parcel(29463): Caused by: java.lang.NoClassDefFoundError: abc/com/android/send_app/ParcelableObject
11-18 09:52:39.444: E/Parcel(29463): ... 24 more
11-18 09:52:39.444: E/Parcel(29463): Caused by: java.lang.ClassNotFoundException: Didn't find class "abc.com.android.send_app.ParcelableObject" on path: DexPathList[[zip file "/data/app/def.com.android.receive_app-2.apk"],nativeLibraryDirectories=[/data/app-lib/def.com.android.receive_app-2, /vendor/lib, /system/lib]]
11-18 09:52:39.444: E/Parcel(29463): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-18 09:52:39.444: E/Parcel(29463): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-18 09:52:39.444: E/Parcel(29463): ... 24 more
Click to expand...
Click to collapse
Hello,
Parcable objects are not very convenient. I have used these kind of objects in previous apps and it was a pain ...
I move to JSON objects to communicate between Activities and (in your case) between apps. No need to share same object between apps because you manage only JSON / String.
I guess you would have a lot of refactoring to do if you move to JSON but I think it is a good way overall if you are stucked for a while.
What do you think about it ?
Regards,

Categories

Resources