2014-04-17 56 views
0

main2.xml显然没有错误。 main.xml也是一样,但我认为问题出在某处。
该应用程序的快速总结:它旨在使用谷歌地图onClick按钮,但我收到错误,所以我可以只加载测试主菜单。 XML
我没有足够的代表张贴图片,以便错误PIC可以发现here我无法让Google Maps API在我的Android应用程序(V2)上工作

main2.xml

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

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:name="com.google.android.gms.maps.MapFragment"/> 

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Club Deals" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="GPS locations" /> 
    <Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Closest Deals" 
     android:onClick="open_close_deals" /> 

    <Button 
     android:id="@+id/button6" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Cheapest Deals" 
     android:onClick="open_cheap_deals" /> 


    <Button 
     android:id="@+id/button7" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Best Value Deals" 
     android:onClick="best_value" /> 

    <Button 
     android:id="@+id/button8" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Best Events" 
     android:onClick="best_events" /> 

    <Button 
     android:id="@+id/button9" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="News" 
     android:onClick="news"/> 
</LinearLayout> 

AppActivity.java

在AppActivity我给 “地图不能得到解决或不是场” &“MAIN2不能得到解决或不是场”

package com.example.clubnightsdeals; 
import android.R; 
import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 

public class AppActivity extends Activity { 

    Button button; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    // addListenerOnButton(); 
    } 

    public void addListenerOnButton() { 

     final Context context = this; 
     button = (Button) findViewById(R.id.button1); 
     button.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

       Intent intent = new Intent(getApplicationContext(), App2Activity.class); 
       startActivity(intent); 

      } 
     }); 
    }; 
     public void addListenerOnButtonNews() { 

     final Context context = this; 

     button = (Button) findViewById(R.id.button9); 

     button.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

       Intent intent = new Intent(getApplicationContext(), App2Activity.class); 
       startActivity(intent); 

      } 
     }); 

     }; 

    /* protected void onCreate1(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.main2); 
      } 

     */ 
     // Google Map 
     GoogleMap googleMap; 

     protected void onCreate1(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main2); 

      try { 
       // Loading map 
       initilizeMap(); 

      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

     } 

     /** 
     * function to load map. If map is not created it will create it for you 
     * */ 
     private void initilizeMap() { 
      if (googleMap == null) { 
       googleMap = ((MapFragment) getFragmentManager().findFragmentById(
         R.id.map)).getMap(); 

       // check if map is created successfully or not 
       if (googleMap == null) { 
        Toast.makeText(getApplicationContext(), 
          "Sorry! unable to create maps", Toast.LENGTH_SHORT) 
          .show(); 
       } 
      } 
     } 

     @Override 
     protected void onResume() { 

      super.onResume(); 
      initilizeMap(); 
     } 

}  

App2Activity我给出的错误“进口com.example.clubnightsdeals.R不能得到解决”

App2Activity.java

package com.example.clubnightsdeals; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.Button; 
import com.example.clubnightsdeals.R; 

public class App2Activity extends Activity { 

    Button button; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main2); 
    } 
} 

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.clubnightsdeals" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <permission 
     android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 
    <uses-sdk 
     android:minSdkVersion="12" 
     android:targetSdkVersion="18" /> 
    <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" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    <!-- Required to show current location --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <!-- Required OpenGL ES 2.0. for Maps V2 --> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/clubnightsdeals" 
      android:name=".AppActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <uses-library 
     android:name="com.google.android.maps" /> 
     <activity 
      android:label="@string/clubnightsdeals" 
      android:name=".App2Activity" > 
     </activity> 

     <meta-data 
    android:name="com.google.android.maps.v2.API_KEY" 
    android:value="AIzaSyDetfYqNFORnvtR245fht3RIK25T6DRY" /> 
       <activity 
            android:name="info.androidhive.googlemapsv2.MainActivity" 
            android:label="@string/app_name" 
            android:theme="@style/AppBaseTheme"> 
            <intent-filter> 
                <action android:name="android.intent.action.MAIN" /> 
  
                <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter> 
        </activity> 
    </application> 



</manifest> 
+0

你必须在你的活动中输入“com.example.clubnightsdeals.R;' –

+0

尝试'main2.xml'将'fragment'放入'FrameLayout'中,或者将fragment的类设置为'SupportMapFragment'。 –

+0

你的最低api水平是多少? – GrIsHu

回答

0

您都指向错误的R.java文件。更换你的下面的导入线

import android.R; 

import com.example.clubnightsdeals.R; 
在AppActivity.java文件

+0

嘿,我把它放进来,但现在我得到了import com.example.clubnightsdeals。R无法解决 – user2849976

+0

更换该行后,您需要清理一次该项目。 – Kedarnath

+0

嘿,已经做了错误似乎仍然存在。 http://i.imgur.com/wTP9kaX.png我已经添加了这张图片,显示控制台 – user2849976

0

您的错误表明您尚未关闭清单文件中的<activity>标记。
确保您已关闭你的活动标签为<activity android:name=""...../><activity android:name=""> </activity>

+0

感谢您的帮助。我把它发布在描述中。据我所知,我确实关闭了它(显然我错了)。 – user2849976

+0

@ user2849976那么我猜你的问题现在已经解决了。 – Kedarnath

+0

不,我的意思是它似乎已经关闭了。它仍然给我同样的错误虽然/ – user2849976

0

首先拆下

<intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

清单中(不能在应用程序开始2活动),然后尝试导入[R库。
如果它仍然存在此R错误,请检查您的xml文件 - 确保检查所有xml文件。

相关问题