Reputation: 1104
I am getting the following problems (As displayed in LogCat). I hope that any1 can help me out with this since i am new to android application development.
11-17 16:50:38.087: E/AndroidRuntime(372): FATAL EXCEPTION: main
11-17 16:50:38.087: E/AndroidRuntime(372): java.lang.IllegalStateException: Could not execute method of the activity
11-17 16:50:38.087: E/AndroidRuntime(372): at android.view.View$1.onClick(View.java:2072)
11-17 16:50:38.087: E/AndroidRuntime(372): at android.view.View.performClick(View.java:2408)
11-17 16:50:38.087: E/AndroidRuntime(372): at android.view.View$PerformClick.run(View.java:8816)
11-17 16:50:38.087: E/AndroidRuntime(372): at android.os.Handler.handleCallback(Handler.java:587)
11-17 16:50:38.087: E/AndroidRuntime(372): at android.os.Handler.dispatchMessagev(Handler.java:92)
11-17 16:50:38.087: E/AndroidRuntime(372): at android.os.Looper.loop(Looper.java:123)
11-17 16:50:38.087: E/AndroidRuntime(372): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-17 16:50:38.087: E/AndroidRuntime(372): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 16:50:38.087: E/AndroidRuntime(372): at java.lang.reflect.Method.invoke(Method.java:521)
11-17 16:50:38.087: E/AndroidRuntime(372): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-17 16:50:38.087: E/AndroidRuntime(372): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-17 16:50:38.087: E/AndroidRuntime(372): at dalvik.system.NativeStart.main(Native Method)
11-17 16:50:38.087: E/AndroidRuntime(372): Caused by: java.lang.reflect.InvocationTargetException
11-17 16:50:38.087: E/AndroidRuntime(372): at com.mspl.activities.AlertListActivity.doShow(AlertListActivity.java:144)
11-17 16:50:38.087: E/AndroidRuntime(372): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 16:50:38.087: E/AndroidRuntime(372): at java.lang.reflect.Method.invoke(Method.java:521)enter code here
11-17 16:50:38.087: E/AndroidRuntime(372): at android.view.View$1.onClick(View.java:2067)
11-17 16:50:38.087: E/AndroidRuntime(372): ... 11 more
11-17 16:50:38.087: E/AndroidRuntime(372): Caused by: java.lang.NoClassDefFoundError: com.mspl.activities.AlertLocationActivity
11-17 16:50:38.087: E/AndroidRuntime(372): ... 15 more
11-17 16:50:38.087: E/AndroidRuntime(372): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
11-17 16:50:38.087: E/AndroidRuntime(372): at dalvik.system.DexFile.defineClass(Native Method)
11-17 16:50:38.087: E/AndroidRuntime(372): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
11-17 16:50:38.087: E/AndroidRuntime(372): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
11-17 16:50:38.087: E/AndroidRuntime(372): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-17 16:50:38.087: E/AndroidRuntime(372): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-17 16:50:38.087: E/AndroidRuntime(372): ... 15 more
This is my AlertListActivity.java file:-
package com.mspl.activities;
enter code here
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class AlertListActivity extends ListActivity {
static final ArrayList<HashMap<String, String>> list2 = new ArrayList<HashMap<String, String>>();
Date date;
HashMap<String, String> map = new HashMap<String, String>();
static int flag = 0;
SimpleAdapter a;
int selectedIndex = 0;
// AlertAdapter sa;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.alert);
//addContentView(R.layout.crowview,new ViewGroup.LayoutParams(this));
SimpleAdapter adapter = new SimpleAdapter(this, list2, R.layout.crowview, new String[] { "alert_type", "date", "identity"}, new int[] { R.id.alarmType, R.id.date, R.id.identity});
populateList();
a = adapter;
setListAdapter(adapter);
}
public void populateList() //Statically filling the ArrayList with HashMap values
{
if (flag == 0) // For entry to be entered only once
{
flag = 1;
map.put("alert_type", "Alert_1");
date = new Date(121, 11, 9, 17, 5, 00);
map.put("date", date.toString());
map.put("identity", "9001");
list2.add(map);
map = new HashMap<String, String>();
map.put("alert_type", "Alert_2");
date = new Date(111, 11, 9, 17, 5, 05);
map.put("date", date.toString());
map.put("identity", "9002");
list2.add(map);
map = new HashMap<String, String>();
map.put("alert_type", "Alert_3");
date = new Date(111, 11, 9, 17, 5, 10);
map.put("date", date.toString());
map.put("identity", "9003");
list2.add(map);
map = new HashMap<String, String>();
map.put("alert_type", "Alert_4");
date = new Date(111, 11, 9, 17, 5, 15);
map.put("date", date.toString());
map.put("identity", "9004");
list2.add(map);
map = new HashMap<String, String>();
map.put("alert_type", "Alert_5");
date = new Date(111, 11, 9, 17, 5, 20);
map.put("date", date.toString());
map.put("identity", "9005");
list2.add(map);
}
}
public void onAck(View view) //Performs Delete operation on Alert List
{
ListView lv1 = getListView();
// long i2 = lv1.getSelectedItemPosition();
//lv1.setSelection(i2);
// int i3 = view.getId();
//list2.remove(i2);
LinearLayout llv = (LinearLayout)view.getParent().getParent();
LinearLayout llv2 = (LinearLayout)llv.getChildAt(0);
TextView child = (TextView)llv2.getChildAt(0);
//Toast.makeText(getApplicationContext(),((TextView)child).getText(), Toast.LENGTH_SHORT).show();
for(int i=0 ; i<list2.size() ; i++)
{
HashMap<String, String> hm = list2.get(i);
String str = hm.get("identity");
if(str.equals(child.getText()))
{
list2.remove(i);
break;
}
}
lv1.refreshDrawableState();
a.notifyDataSetChanged();
a.notifyDataSetInvalidated();
}
public void doShow(View view)
{
try{
Intent intent = new Intent(AlertListActivity.this, AlertLocationActivity.class);
startActivity(intent);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) //Listener for ListView Item click
{
super.onListItemClick(l, v, position, id);
selectedIndex = position;
Object o = this.getListAdapter().getItem(position);
String str = o.toString();
// Toast.makeText(this, "You have chosen: " + " " + str,
// Toast.LENGTH_LONG).show();
Intent i = new Intent(this, AlertDetailsActivity.class);
i.putExtra("str", str);
startActivity(i);
}
}
This is my AlertLocationActivity.java file:-
package com.mspl.activities;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class AlertLocationActivity extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
MapView mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
The AndroidManifest.xml file:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mspl.activities" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShowVehicleListActivity"
android:label="@string/vehicle.list.screen" />
<activity android:name=".AlertListActivity"
android:label="@string/alert.list.screen" />
<activity android:name=".AlertDetailsActivity"
android:label="@string/alert2.list.screen" />
<uses-library android:name="com.google.android.maps" />
<activity android:name=".AlertLocationActivity"
android:label="@string/alert.loc.screen" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
</manifest>
And this is my mapview.xml file:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0WYMWNJ2XW382cucH2luf4o6bRtkU7W6vROnlrg"
/>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Upvotes: 1
Views: 1346
Reputation: 1104
I have solved it.
Problem was that two Google API libraries were getting referenced even though it was not displaying the Google API folder. I guess this must have happened since i had installed the Google maps plugin after i had created the application in which i was using it.
Solution was to remove the reference to "maps.jar" in the "Configure Build Path" and then create a new Android Project and simply copy-paste the Google APIs folder into my current project.
Thanx anyways though guys...
Upvotes: 3
Reputation: 29968
Have you added
<uses-library android:name="com.google.android.maps" />
inside < application > tag in Manifest
file ?
Also check Cannot resolve MapActivity class on Android
Upvotes: 1