从另一个类点击按钮打开mapview

时间:2010-11-16 11:55:10

标签: java android android-intent android-mapview

我不明白这里似乎有什么问题......我的应用只是崩溃了。 我得到以下logcat错误: ERROR / dalvikvm(1270):找不到类'intentTest.xyz.com.second',从方法intentTest.xyz.com.intentTest引用$ 1.onClick

1.intentTest.java:

package intentTest.xyz.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class intentTest extends Activity {
  Button b;
  /** Called when the activity is first created. */
   @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b = (Button) findViewById(R.id.b);

    b.setOnClickListener( new View.OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent(intentTest.this,second.class );
            startActivity(intent);                
        }
    });

   }
 }

2.main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="First screen"
/>

<Button
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="map"
android:id="@+id/b"
/>
</LinearLayout>

3.second.java:

 package intentTest.xyz.com;

 import com.google.android.maps.MapActivity;
 import com.google.android.maps.MapView;
 import android.os.Bundle;

 public class second extends MapActivity{
  MapView map;
  /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);
   map = (MapView) findViewById(R.id.map);
   }

 @Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
 return false;
  }
  }

4.second.xml:

<?xml version="1.0" encoding="utf-8"?>


<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"        
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0ujyc9Tw2cYvyPECIKTQIK0pwuL-UPa_sh4BpIw"
/>

5.manifest.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="intentTest.xyz.com"
  android:versionCode="1"
  android:versionName="1.0">


<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".intentTest"
              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=".second"
          android:label="@string/app_name">
           <uses-library android:name="com.google.android.maps" />
   </activity>

   </application>

  <uses-permission android:name="android.permission.INTERNET" />

  </manifest> 

1 个答案:

答案 0 :(得分:0)

没关系......我重写了整个代码....一步一步......遵守它然后得到了输出....可能是一个编译器问题