我是android开发的新手......我在android上创建了一个项目,其中菜单页面将有四个图像按钮...通过点击其中一个按钮,我可以打开谷歌地图。其他三个按钮是工作正常,但按钮将带我googlemaps不工作。我点击该按钮后,应用程序强行关闭,消息应用程序意外停止。我的java页面在这里
package com.drugindexx.demo;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.drugindexx.others.Prefs;
public class MenuOptions extends Activity{
private ImageButton ibtnIndex,ibtnSearch,ibtnProfile,ibtnSettings;
private String selectedbackground;
RelativeLayout rltv_main;
RelativeLayout rltv_header;
String user;
Button btn_logout;
TextView tv_name;
String Firstname;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
rltv_header = (RelativeLayout) findViewById(R.id.RLHeader);
rltv_main = (RelativeLayout) findViewById(R.id.RLMain);
ibtnIndex=(ImageButton)findViewById(R.id.imgbtnDoctor);
ibtnSearch=(ImageButton)findViewById(R.id.imgbtnGmap);
ibtnProfile=(ImageButton)findViewById(R.id.imgbtnProfile);
ibtnSettings=(ImageButton)findViewById(R.id.imgbtnSetting);
btn_logout= (Button)findViewById(R.id.btn_logout);
tv_name= (TextView)findViewById(R.id.txtvw_name);
LoadPreferences();
/*if (getIntent().getExtras().getString("user") == null){
user="";
}
else{
user= getIntent().getExtras().getString("user");
}
if(getIntent().getExtras().getString("fname")== null){
Firstname= "";
}
else{
Firstname= getIntent().getExtras().getString("fname");
}*/
if(getIntent().getStringExtra("user") != null){
user = getIntent().getStringExtra("user");
}
if(getIntent().getStringExtra("fname") != null){
Firstname = getIntent().getStringExtra("fname");
tv_name.setText(Firstname);
}
ibtnSettings.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SavePreferences("username", user);
Intent i=new Intent(getApplicationContext(),Settings.class);
startActivity(i);
}
});
//ibtnSearch=(ImageButton)findViewById(R.id.imgbtnGmap);
ibtnSearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SavePreferences("username", user);
startActivity(new Intent(MenuOptions.this,G.class));
//startActivity(i);
}
});
ibtnProfile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SavePreferences("username", user);
Intent i=new Intent(getApplicationContext(),UserDetails.class);
i.putExtra("user", user);
startActivity(i);
}
});
ibtnIndex.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SavePreferences("username", user);
Intent i=new Intent(getApplicationContext(),SarchIndx.class);
startActivity(i);
}
});
btn_logout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SavePreferences("username", user);
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
String strSavedMem1 = sharedPreferences.getString("phn_no", "");
strSavedMem1= "";
String strSavedMem2 = sharedPreferences.getString("text", "");
strSavedMem2= "";
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove("phn_no");
editor.remove("text");
editor.remove("MEM1");
editor.remove("MEM2");
editor.commit();
Intent i=new Intent(getApplicationContext(),LoginPage.class);
startActivity(i);
}
});
}
@Override
protected void onResume() {
super.onResume();
Prefs pref = new Prefs(MenuOptions.this);
selectedbackground = pref.getbackground();
setbackgroundtothisscreen();
}
private void setbackgroundtothisscreen() {
if (selectedbackground.contains("Red")) {
rltv_main.setBackgroundResource(R.drawable.background_red);
rltv_header.setBackgroundResource(R.drawable.topbar_red);
} else if (selectedbackground.contains("Blue")) {
rltv_main.setBackgroundResource(R.drawable.background_blue);
rltv_header.setBackgroundResource(R.drawable.topbar_blue);
} else if (selectedbackground.contains("Green")) {
rltv_main.setBackgroundResource(R.drawable.background_green);
rltv_header.setBackgroundResource(R.drawable.topbar_green);
}
}
protected void SavePreferences(String key, String value) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
private void LoadPreferences() {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
user = sharedPreferences.getString("username", "");
}
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
这是xml页面:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RLMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/midbg" >
<RelativeLayout
android:id="@+id/RLHeader"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/topbar_red" >
<TextView
android:id="@+id/txtvw_topbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textColor="@color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/txtvw_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="@+id/txtvw_topbar"
android:textColor="@color/white"/>
<Button
android:id="@+id/btn_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout"
android:layout_marginLeft="250dp"
android:background="@drawable/blankblack"
android:textColor="@color/white"
android:layout_marginTop="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/RLBody"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/RLHeader"
android:layout_marginTop="20dp">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rltv_mainrltv" >
<RelativeLayout
android:id="@+id/rltv_dtlshldr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<RelativeLayout
android:id="@+id/rl01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imgbtnDoctor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/doctor" />
<ImageButton
android:id="@+id/imgbtnGmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/gmap" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl02"
android:layout_below="@+id/rl01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="50dp"
>
<ImageButton
android:id="@+id/imgbtnProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="37dp"
android:src="@drawable/profile" />
<ImageButton
android:id="@+id/imgbtnSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="26dp"
android:src="@drawable/setting" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
地图的.java页面是:
package com.drugindexx.demo;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class G extends MapActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.g);
MapView mapView = (MapView) findViewById(R.id.map);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
地图的xml页面是:
<?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" >
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0VSKb6B9mzGfO7Ic6cKeMOZSh-8hJYOd7a4YZ3A"
android:clickable="true"
/>
</LinearLayout>
现在我在这里给出错误::
04-02 19:23:36.111: E/AndroidRuntime(567): FATAL EXCEPTION: main
04-02 19:23:36.111: E/AndroidRuntime(567): java.lang.NoClassDefFoundError: com.drugindexx.demo.G
04-02 19:23:36.111: E/AndroidRuntime(567): at com.drugindexx.demo.MenuOptions$2.onClick (MenuOptions.java:84)
04-02 19:23:36.111: E/AndroidRuntime(567): at android.view.View.performClick(View.java:2408)
04-02 19:23:36.111: E/AndroidRuntime(567): at android.view.View$PerformClick.run(View.java:8816)
04-02 19:23:36.111: E/AndroidRuntime(567): at android.os.Handler.handleCallback(Handler.java:587)
04-02 19:23:36.111: E/AndroidRuntime(567): at android.os.Handler.dispatchMessage(Handler.java:92)
04-02 19:23:36.111: E/AndroidRuntime(567): at android.os.Looper.loop(Looper.java:123)
04-02 19:23:36.111: E/AndroidRuntime(567): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-02 19:23:36.111: E/AndroidRuntime(567): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 19:23:36.111: E/AndroidRuntime(567): at java.lang.reflect.Method.invoke(Method.java:521)
04-02 19:23:36.111: E/AndroidRuntime(567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-02 19:23:36.111: E/AndroidRuntime(567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-02 19:23:36.111: E/AndroidRuntime(567): at dalvik.system.NativeStart.main(Native Method)
04-02 19:23:36.111: E/AndroidRuntime(567): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
04-02 19:23:36.111: E/AndroidRuntime(567): at dalvik.system.DexFile.defineClass(Native Method)
04-02 19:23:36.111: E/AndroidRuntime(567): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
04-02 19:23:36.111: E/AndroidRuntime(567): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
04-02 19:23:36.111: E/AndroidRuntime(567): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-02 19:23:36.111: E/AndroidRuntime(567): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-02 19:23:36.111: E/AndroidRuntime(567): ... 12 more
这是先生...努力尝试但无法纠正我的错误......我是编程的新手...寻找你的帮助