开发者

ERROR/dalvikvm(1399): Could not find class 'maptest.xyz.com.maps', referenced from method maptest.xyz.com.maptest$1.onClick

The problem is that if i use these two lines of code,my app closes unxepectedly and if not used, the app works just fine...is there any other way to get to the maps.class? The following is the code i used:

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

the following is my manifest file:

 <?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;
    }
}


Your tag <uses-library android:name="com.google.android.maps" /> has to be inside the <application> tag!

manifest has to be like this:

 <?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>


Try:

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


Activity (Class) name must start with capital letter, and instead of using BlobCity.this use only "this" keyword which refers the Context of the current Activity

e.g.

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

also make sure entry of this Activity must be in your AndroidManifest.xml file

e.g.

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

also you can follow a great tutorial on Android Google Maps here :

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜