我有一个Android微调器或数组适配器错误,但我不确定

时间:2013-07-17 10:30:07

标签: java android android-intent google-maps-android-api-2

我是Android程序员的新手。

我有一个微调器或适配器方法或其他错误。我创建一个下拉微调器并使用数组适配器方法调用整数数组但有些错误,请参阅此错误。

07-17 13:46:42.496: E/AndroidRuntime(7501): FATAL EXCEPTION: main
07-17 13:46:42.496: E/AndroidRuntime(7501): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mpa.emvi/com.mpa.emvi.HomeActivity}: java.lang.InstantiationException: can't instantiate class com.mpa.emvi.HomeActivity
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.ActivityThread.access$700(ActivityThread.java:152)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.os.Looper.loop(Looper.java:137)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.ActivityThread.main(ActivityThread.java:5328)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at java.lang.reflect.Method.invokeNative(Native Method)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at java.lang.reflect.Method.invoke(Method.java:511)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at dalvik.system.NativeStart.main(Native Method)
07-17 13:46:42.496: E/AndroidRuntime(7501): Caused by: java.lang.InstantiationException: can't instantiate class com.mpa.emvi.HomeActivity
07-17 13:46:42.496: E/AndroidRuntime(7501):     at java.lang.Class.newInstanceImpl(Native Method)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at java.lang.Class.newInstance(Class.java:1319)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
07-17 13:46:42.496: E/AndroidRuntime(7501):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
07-17 13:46:42.496: E/AndroidRuntime(7501):     ... 11 more

这是我的类文件

public abstract class HomeActivity extends FragmentActivity 
 implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener, OnItemSelectedListener {

    private CheckBox mTrafficCheckbox;

    private LocationManager mLocationManager;
    boolean statusOfGPS;
    private GoogleMap mMap;
    private LocationClient mLocationClient;
    private String DescribText = new String();

    private static final String TAG = "MyGPS_status";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);   

        Spinner spinner = (Spinner) findViewById(R.id.spinner1);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.layers_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);

        mTrafficCheckbox = (CheckBox) findViewById(R.id.checkBox1);

        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
        if (mMap != null) {
            updateTraffic();
            setUpLocationClientIfNeeded();
            mLocationClient.connect();
            mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE );
        }
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                 mMap.setMyLocationEnabled(true);
            }
        }
    }

    private void setUpLocationClientIfNeeded() {
        if (mLocationClient == null) {
          mLocationClient = new LocationClient(
              getApplicationContext(),
              this,  // ConnectionCallbacks
              this); // OnConnectionFailedListener
        }
     }

    public void sendEmail(View view){
        statusOfGPS = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        final Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","suphawut@mpatmail.com", null));

        if (mLocationClient != null && mLocationClient.isConnected() && statusOfGPS == true) {
            DescribText = "(For Test Emergency App)"+ 
                    "This is My Emergency Location on GPS " +
                    " <a href='https://maps.google.com/maps?q="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&ll="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&z=17'>click here</a>";

            i.putExtra(Intent.EXTRA_SUBJECT, "Emergency Location");
            i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(DescribText));
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_LONG).show();
            }

         Log.d(TAG, "gps =" + statusOfGPS);
        }else{
            DescribText = "This is My Emergency Location on INTERNET" +
                    " <a href='https://maps.google.com/maps?q="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&ll="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&z=17'>click here</a>";
            i.putExtra(Intent.EXTRA_SUBJECT, "Emergency Location");
            i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(DescribText));
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_LONG).show();
            }

          Log.d(TAG, "gps =" + statusOfGPS);                 
        }
    }


    @Override
    protected void onPause() {
        super.onPause();

    }

    /**
     * Callback called when disconnected from GCore. Implementation of {@link ConnectionCallbacks}.
     */
    @Override
    public void onDisconnected() {
      // Do nothing
    }

    /**
     * Implementation of {@link OnConnectionFailedListener}.
     */
    @Override
    public void onConnectionFailed(ConnectionResult result) {
      // Do nothing
    }

    @Override
    public void onLocationChanged(Location arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onConnected(Bundle arg0) {
        // TODO Auto-generated method stub

    }
    public void onProviderEnable(String provider){

    }
    public void onTrafficToggled(View view) {
        updateTraffic();
    }

    private void updateTraffic() {

        mMap.setTrafficEnabled(mTrafficCheckbox.isChecked());
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        setLayer((String) parent.getItemAtPosition(position));
    }

    private void setLayer(String layerName) {
        if (layerName.equals(getString(R.string.normal))) {
            mMap.setMapType(MAP_TYPE_NORMAL);
        } else if (layerName.equals(getString(R.string.hybrid))) {
            mMap.setMapType(MAP_TYPE_HYBRID);
        } else if (layerName.equals(getString(R.string.satellite))) {
            mMap.setMapType(MAP_TYPE_SATELLITE);
        } else if (layerName.equals(getString(R.string.terrain))) {
            mMap.setMapType(MAP_TYPE_TERRAIN);
        } else {
            Log.i("LDA", "Error setting layer with name " + layerName);
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }
}

我不确定问题可能是微调器,阵列适配器或其他什么,但感谢任何答案。

P.S。我的英语技能很差。

2 个答案:

答案 0 :(得分:1)

为什么要进行abstract课程。只需删除类的抽象性。

答案 1 :(得分:0)

请检查你的Androidmanifest.xml,你是否给出了正确的名称,如.HomeActivity或(完整包).HomeActivity,如果没有,那么使其正确,然后清理你的项目。

如果不需要,则删除抽象标签。