2010-11-15 25 views
0

問題是,如果我使用這兩行代碼,我的應用程序意外關閉,如果不使用,應用程序工作得很好......是否有其他方法可以訪問maps.class? 下面是我使用的代碼:

 Intent in = new Intent(BlobCity.this, maps.class) 
     startActivity(in); 

以下是我的清單文件:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="BlobCity.xyz.com" 
    android:versionCode="1" 
    android:versionName="1.0"> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-library android:name="com.google.android.maps" /> 
<application android:icon="@drawable/icon" android:label="@string/app_name">  
    <activity android:name=".BlobCity" 
       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=".maps" /> 
    </application> 

     </manifest> 

blobcity.java:

public class BlobCity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    Button signIn,register; 
    TextView Blob,City,username,password; 
    EditText eUsername,ePassword; 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     signIn = (Button) findViewById(R.id.signIn); 
     register = (Button) findViewById(R.id.register); 

     Blob = (TextView) findViewById(R.id.blob); 
     City = (TextView) findViewById(R.id.city); 
     username = (TextView) findViewById(R.id.username); 
     password = (TextView) findViewById(R.id.password); 

     eUsername = (EditText) findViewById(R.id.eUsername); 
     ePassword = (EditText) findViewById(R.id.ePassword); 

     signIn.setOnClickListener(new sendUserPass()); 
     register.setOnClickListener(new regPage()); 
    } 

    class sendUserPass implements Button.OnClickListener 
    { 
     public void onClick(View v) 
     { 
      String uname = eUsername.getText().toString(); 
      String pwd = ePassword.getText().toString(); 
      String requestString = ("http://192.168.1.102:8080/BlobCity/RemoteLogin?email="+ uname + "&pwd=" + pwd); 
      String line; 

      try { 
       HttpResponse response = new DefaultHttpClient().execute(new HttpGet(requestString)); 
       InputStream is = response.getEntity().getContent(); 
       BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
       StringBuilder rb = new StringBuilder(""); 

       while ((line=br.readLine()) != null) 
       { 
        rb.append(line) ; 
       } 
       if(rb.toString().equals("0")) 
       { 
        Toast toast = Toast.makeText(getApplicationContext(), "Please enter a valid Username and/or Password!", Toast.LENGTH_LONG); 
        toast.show(); 
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 

        eUsername.setText(""); 
        ePassword.setText(""); 
       } 
       else 
       { 
        Intent in = new Intent(BlobCity.this, maps.class); 
        startActivity(in); 
        eUsername.setText(""); 
        ePassword.setText(""); 
       } 
      } 
      catch (ClientProtocolException e) 
      { 
       e.printStackTrace(); 
      } 
      catch (IOException e) 
      { 
       e.printStackTrace(); 
      } 
     } 
    } 

    class regPage implements Button.OnClickListener 
    { 
     public void onClick(View v) 
     { 
      Intent browse = new Intent(Intent.ACTION_VIEW , Uri.parse("http://www.blobcity.com")); 
      startActivity(browse); 
     } 
    } 
} 

maps.java:

import android.os.Bundle; 

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

public class maps extends MapActivity{ 
    MapView mapView; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 
     mapView = (MapView) findViewById(R.id.map); 
    } 
    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 
} 
+0

什麼是您的日誌說?任何錯誤? – 2010-11-15 09:32:23

+0

沒有...應用程序只是停止並強制關閉時使用這段代碼 – heha 2010-11-15 09:35:53

+0

日誌請???????? – viv 2010-11-15 09:55:01

回答

0

嘗試:

Intent in = new Intent(BlobCity.this.getApplicationContext(), maps.class) 
startActivity(in); 
+0

nope ... that does not工作 – heha 2010-11-15 09:39:50

+0

11-15 21:59:28.827:錯誤/ dalvikvm(1399):無法找到類'maptest.xyz.com.maps',從方法maptest.xyz.com.maptest引用$ 1.onClick – heha 2010-11-16 06:00:51

0

Activity (Class)名必須以大寫字母開始,而不是使用BlobCity.this僅使用「this」關鍵字是指當前Activity

例如在Context

Intent in = new Intent(this, Maps.class) 
startActivity(in); 

也讓這款Activity的肯定條目必須是在你的AndroidManifest.xml文件

例如

<activity android:name=".Maps"></activity> 

你也可以按照在Android谷歌地圖一個偉大的教程在這裏:

http://mobiforge.com/developing/story/using-google-maps-android

+0

我已經完成無論你在上面提到過......但這似乎並不能解決問題。 – heha 2010-11-15 10:00:51

+0

如果可能的話,發佈你的整個代碼片段,或者只是發佈eclipse LogCat視圖中的錯誤日誌 – 2010-11-15 11:09:41

+0

查看片段 – heha 2010-11-15 11:38:47

1

你的標籤<uses-library android:name="com.google.android.maps" />必須<application>標籤內!

清單必須是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="BlobCity.xyz.com" 
    android:versionCode="1" 
    android:versionName="1.0"> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<application android:icon="@drawable/icon" android:label="@string/app_name">  
    **<uses-library android:name="com.google.android.maps" />** 
    <activity android:name=".BlobCity" 
       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=".maps" /> 
</application> 
</manifest> 
相關問題