0

我是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.
    }
}

我不确定问题可能是微调器、阵列适配器或其他东西,但感谢您的任何回答。

PS我的英语水平很差。

4

2 回答 2

1

你为什么要abstract 上课。只需删除类的抽象性。

于 2013-07-17T10:35:30.383 回答
0

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

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

于 2013-07-17T10:42:14.163 回答