Я получаю 2 ошибки на}

Хе-хе, спасибо всем за ответ, я довольно новичок в этом, и вы все мне очень помогли здесь. Тины исправлены, приложение работает так, как я хотел. Я думаю, что не могу закрыть вопрос, но это для меня ужасно ^^

У меня есть расширяемый список.

Все, что ниже, это мой MainActivity.java

В нем есть 2 ошибки, обе на a }.

Я убежден, что они правильно размещены. попытался обновить программное обеспечение и т.д., но я не могу заставить ошибки исчезнуть по какой-то причине.

Это самый последний} и тот, что перед возвращением false }

код начинается здесь:

package com.example.sk17;


import com.example.adapterr.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;

public class MainActivity extends Activity {

ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // get the listview
    expListView = (ExpandableListView) findViewById(R.id.lvExp);

    // preparing list data
    prepareListData();

    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

    // setting list adapter
    expListView.setAdapter(listAdapter);



}


private OnChildClickListener myListItemClicked =  new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
   Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
          Toast.LENGTH_SHORT).show();
  // Go to child #0 specific class.
  Intent child0Intent = new Intent(this, activity0.class);
  startActivity(Intent);

}

  return false;
}
/*
 * Preparing the list data
 */
  private void prepareListData() {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();

    // Adding child data
    listDataHeader.add("1 SAFETY PRECAUTIONS");
    listDataHeader.add("2 MACHINE FAMILIARIZATION");
    listDataHeader.add("3 MACHINE OPERATION");
    listDataHeader.add("4 MAINTENANCE");
    listDataHeader.add("5 TRANSPORTATION");
    listDataHeader.add("6 SPECIFICATIONS");
    listDataHeader.add("7 OPTIONAL EQUIPMENT");
    listDataHeader.add("8 TROUBLESHOOTING");
    listDataHeader.add("9 SPECIAL PROCEDURES");

    // Adding child data
    List<String> SAFETYPRECAUTIONS = new ArrayList<String>();
    SAFETYPRECAUTIONS.add("1.1 GENERAL SAFETY INFORMATION");
    SAFETYPRECAUTIONS.add("1.2 SAFETY PRECAUTIONS");
    SAFETYPRECAUTIONS.add("1.3 PRE-START SAFETY");
    SAFETYPRECAUTIONS.add("1.4 SAFETY DURING OPERATION");
    SAFETYPRECAUTIONS.add("1.5 INSPECTION & MAINTENANCE SAFETY");
    SAFETYPRECAUTIONS.add("1.6 BATTERY SAFETY");
    SAFETYPRECAUTIONS.add("1.7 WARNING LABELS & DECALS");
    SAFETYPRECAUTIONS.add("1.8 PROHIBITED MACHINE OPERATION");
    SAFETYPRECAUTIONS.add("1.9 END OF WORK SHIFT SAFETY");
    SAFETYPRECAUTIONS.add("1.10 TRANSPORTATION");
    SAFETYPRECAUTIONS.add("1.11 TOWING THE MACHINE");

    List<String> MACHINEFAMILIARIZATION = new ArrayList<String>();
    MACHINEFAMILIARIZATION.add("2.1 FAMILIARIZATION");
    MACHINEFAMILIARIZATION.add("2.2 GENERAL MACHINE NOMENCLATURE");
    MACHINEFAMILIARIZATION.add("2.3 OPERATOR CAB NOMENCLATURE");
    MACHINEFAMILIARIZATION.add("2.4 COMPONENT & CONTROLS NOMENCLATURE");

    List<String> MACHINEOPERATION = new ArrayList<String>();
    MACHINEOPERATION.add("3.1 BASIC MACHINE OPERATION");

    List<String> MAINTENANCE = new ArrayList<String>();
    MAINTENANCE.add("4.1 GENERAL INFORMATION");
    MAINTENANCE.add("4.2 GENERAL SAFETY & PRECAUTIONS");
    MAINTENANCE.add("4.3 LUBRICANT, FUEL & COOLANT SPECIFICATIONS");
    MAINTENANCE.add("4.4 MAINTENANCE PARTS");
    MAINTENANCE.add("4.5 ACCESSORY TOOLS");
    MAINTENANCE.add("4.6 TORQUE SPECIFICATIONS FOR BOLTS & NUTS");
    MAINTENANCE.add("4.7 TORQUE SPECIFICATIONS FOR JOINTS & HYDRAULIC HOSES");
    MAINTENANCE.add("4.8 INSTALLING HYDRAULIC HOSE AND PIPE JOINT FITTINGS");
    MAINTENANCE.add("4.9 RELEASING INTERNAL PRESSURE OF HYDRAULIC SYSTEM");
    MAINTENANCE.add("4.10 BLEEDING AIR IN FUEL SYSTEM");
    MAINTENANCE.add("4.11 REPLACING RUBBER CRAWLER BELT");
    MAINTENANCE.add("4.12 INSPECTION & MAINTENANCE CHART");
    MAINTENANCE.add("4.13 OTHER MAINTENANCE - PERFORMED WHEN REQUIRED");
    MAINTENANCE.add("4.14 PRE-START (EVERY 8 HOURS) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.15 50-HOUR (WEEKLY) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.16 250-HOUR (3-MONTH) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.17 500-HOUR (6-MONTH) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.18 1000-HOUR (12-MONTH) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.19 2000-HOUR INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.20 5000-HOUR INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.21 INSPECTION / MAINTENANCE CHECK LIST");


    List<String> TRANSPORTATION = new ArrayList<String>();
    TRANSPORTATION.add("5.1 PREPARING FOR MACHINE TRANSPORTATION.");
    TRANSPORTATION.add("5.2 LIFTING THE MACHINE");
    TRANSPORTATION.add("5.3 WEIGHT AND DIMENSION SPECIFICATIONS");

    List<String> SPECIFICATIONS = new ArrayList<String>();
    SPECIFICATIONS.add("6.1 GENERAL SPECIFICATIONS");

    List<String> OPTIONALEQUIPMENT = new ArrayList<String>();
    OPTIONALEQUIPMENT.add("7.1 OPERATION OF HYDRAULIC BREAKER AND NIBBLER");
    OPTIONALEQUIPMENT.add("7.2 SAFETY PRECAUTIONS");
    OPTIONALEQUIPMENT.add("7.3 PERIODIC INSPECTION AND MAINTENANCE INTERVAL");

    List<String> TROUBLESHOOTING = new ArrayList<String>();
    TROUBLESHOOTING.add("8.1 GENERAL TROUBLESHOOTING");

    List<String> SPECIALPROCEDURES = new ArrayList<String>();
    SPECIALPROCEDURES.add("9.1 MOVING A DISABLED MACHINE.");
    SPECIALPROCEDURES.add("9.2 RELEASING LOCK ON TRAVEL MOTOR");


    listDataChild.put(listDataHeader.get(0), SAFETYPRECAUTIONS); // Header, Child data
    listDataChild.put(listDataHeader.get(1), MACHINEFAMILIARIZATION);
    listDataChild.put(listDataHeader.get(2), MACHINEOPERATION);
    listDataChild.put(listDataHeader.get(3), MAINTENANCE);
    listDataChild.put(listDataHeader.get(4), TRANSPORTATION);
    listDataChild.put(listDataHeader.get(5), SPECIFICATIONS);
    listDataChild.put(listDataHeader.get(6), OPTIONALEQUIPMENT);
    listDataChild.put(listDataHeader.get(7), TROUBLESHOOTING);
    listDataChild.put(listDataHeader.get(8), SPECIALPROCEDURES);
}


}

4 ответа

Изменить на

private OnChildClickListener myListItemClicked =  new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2,
                int arg3, long arg4) {
            // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
                Toast.LENGTH_SHORT).show();
               // Go to child #0 specific class.
               Intent child0Intent = new Intent(this, activity0.class);
               startActivity(Intent);
            return false;
        }

    }; // statement ends with ;

Это объявление с последующей явной инициализацией и должно заканчиваться ;

Ваши фигурные скобки не верны, и правильный отступ показал бы вам:

private OnChildClickListener myListItemClicked =  new OnChildClickListener() { // open 1
  @Override
  public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // open 2
    Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
          Toast.LENGTH_SHORT).show();
    // Go to child #0 specific class.
    Intent child0Intent = new Intent(this, activity0.class);
    startActivity(Intent);

  } // close 2
  return false;
} // close 1

Это означает, что return false; находится внутри тела класса анонимного внутреннего класса, тогда как оно должно быть в теле метода:

private OnChildClickListener myListItemClicked =  new OnChildClickListener() {1
  @Override
  public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
     Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
          Toast.LENGTH_SHORT).show();
    // Go to child #0 specific class.
    Intent child0Intent = new Intent(this, activity0.class);
    startActivity(Intent);

    return false;
  }
};

Это правильный код: -

    package com.example.sk17;


import com.example.adapterr.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;

public class MainActivity extends Activity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // get the listview
    expListView = (ExpandableListView) findViewById(R.id.lvExp);

    // preparing list data
    prepareListData();

    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

    // setting list adapter
    expListView.setAdapter(listAdapter);



}


private OnChildClickListener myListItemClicked =  new OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
                Toast.LENGTH_SHORT).show();
        // Go to child #0 specific class.
        Intent child0Intent = new Intent(this, activity0.class);
        startActivity(Intent);
        return false; // return statement added here
    }


}; // semicolon added
/*
 * Preparing the list data
 */
private void prepareListData() {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();

    // Adding child data
    listDataHeader.add("1 SAFETY PRECAUTIONS");
    listDataHeader.add("2 MACHINE FAMILIARIZATION");
    listDataHeader.add("3 MACHINE OPERATION");
    listDataHeader.add("4 MAINTENANCE");
    listDataHeader.add("5 TRANSPORTATION");
    listDataHeader.add("6 SPECIFICATIONS");
    listDataHeader.add("7 OPTIONAL EQUIPMENT");
    listDataHeader.add("8 TROUBLESHOOTING");
    listDataHeader.add("9 SPECIAL PROCEDURES");

    // Adding child data
    List<String> SAFETYPRECAUTIONS = new ArrayList<String>();
    SAFETYPRECAUTIONS.add("1.1 GENERAL SAFETY INFORMATION");
    SAFETYPRECAUTIONS.add("1.2 SAFETY PRECAUTIONS");
    SAFETYPRECAUTIONS.add("1.3 PRE-START SAFETY");
    SAFETYPRECAUTIONS.add("1.4 SAFETY DURING OPERATION");
    SAFETYPRECAUTIONS.add("1.5 INSPECTION & MAINTENANCE SAFETY");
    SAFETYPRECAUTIONS.add("1.6 BATTERY SAFETY");
    SAFETYPRECAUTIONS.add("1.7 WARNING LABELS & DECALS");
    SAFETYPRECAUTIONS.add("1.8 PROHIBITED MACHINE OPERATION");
    SAFETYPRECAUTIONS.add("1.9 END OF WORK SHIFT SAFETY");
    SAFETYPRECAUTIONS.add("1.10 TRANSPORTATION");
    SAFETYPRECAUTIONS.add("1.11 TOWING THE MACHINE");

    List<String> MACHINEFAMILIARIZATION = new ArrayList<String>();
    MACHINEFAMILIARIZATION.add("2.1 FAMILIARIZATION");
    MACHINEFAMILIARIZATION.add("2.2 GENERAL MACHINE NOMENCLATURE");
    MACHINEFAMILIARIZATION.add("2.3 OPERATOR CAB NOMENCLATURE");
    MACHINEFAMILIARIZATION.add("2.4 COMPONENT & CONTROLS NOMENCLATURE");

    List<String> MACHINEOPERATION = new ArrayList<String>();
    MACHINEOPERATION.add("3.1 BASIC MACHINE OPERATION");

    List<String> MAINTENANCE = new ArrayList<String>();
    MAINTENANCE.add("4.1 GENERAL INFORMATION");
    MAINTENANCE.add("4.2 GENERAL SAFETY & PRECAUTIONS");
    MAINTENANCE.add("4.3 LUBRICANT, FUEL & COOLANT SPECIFICATIONS");
    MAINTENANCE.add("4.4 MAINTENANCE PARTS");
    MAINTENANCE.add("4.5 ACCESSORY TOOLS");
    MAINTENANCE.add("4.6 TORQUE SPECIFICATIONS FOR BOLTS & NUTS");
    MAINTENANCE.add("4.7 TORQUE SPECIFICATIONS FOR JOINTS & HYDRAULIC HOSES");
    MAINTENANCE.add("4.8 INSTALLING HYDRAULIC HOSE AND PIPE JOINT FITTINGS");
    MAINTENANCE.add("4.9 RELEASING INTERNAL PRESSURE OF HYDRAULIC SYSTEM");
    MAINTENANCE.add("4.10 BLEEDING AIR IN FUEL SYSTEM");
    MAINTENANCE.add("4.11 REPLACING RUBBER CRAWLER BELT");
    MAINTENANCE.add("4.12 INSPECTION & MAINTENANCE CHART");
    MAINTENANCE.add("4.13 OTHER MAINTENANCE - PERFORMED WHEN REQUIRED");
    MAINTENANCE.add("4.14 PRE-START (EVERY 8 HOURS) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.15 50-HOUR (WEEKLY) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.16 250-HOUR (3-MONTH) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.17 500-HOUR (6-MONTH) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.18 1000-HOUR (12-MONTH) INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.19 2000-HOUR INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.20 5000-HOUR INSPECTION AND MAINTENANCE");
    MAINTENANCE.add("4.21 INSPECTION / MAINTENANCE CHECK LIST");


    List<String> TRANSPORTATION = new ArrayList<String>();
    TRANSPORTATION.add("5.1 PREPARING FOR MACHINE TRANSPORTATION.");
    TRANSPORTATION.add("5.2 LIFTING THE MACHINE");
    TRANSPORTATION.add("5.3 WEIGHT AND DIMENSION SPECIFICATIONS");

    List<String> SPECIFICATIONS = new ArrayList<String>();
    SPECIFICATIONS.add("6.1 GENERAL SPECIFICATIONS");

    List<String> OPTIONALEQUIPMENT = new ArrayList<String>();
    OPTIONALEQUIPMENT.add("7.1 OPERATION OF HYDRAULIC BREAKER AND NIBBLER");
    OPTIONALEQUIPMENT.add("7.2 SAFETY PRECAUTIONS");
    OPTIONALEQUIPMENT.add("7.3 PERIODIC INSPECTION AND MAINTENANCE INTERVAL");

    List<String> TROUBLESHOOTING = new ArrayList<String>();
    TROUBLESHOOTING.add("8.1 GENERAL TROUBLESHOOTING");

    List<String> SPECIALPROCEDURES = new ArrayList<String>();
    SPECIALPROCEDURES.add("9.1 MOVING A DISABLED MACHINE.");
    SPECIALPROCEDURES.add("9.2 RELEASING LOCK ON TRAVEL MOTOR");


    listDataChild.put(listDataHeader.get(0), SAFETYPRECAUTIONS); // Header, Child data
    listDataChild.put(listDataHeader.get(1), MACHINEFAMILIARIZATION);
    listDataChild.put(listDataHeader.get(2), MACHINEOPERATION);
    listDataChild.put(listDataHeader.get(3), MAINTENANCE);
    listDataChild.put(listDataHeader.get(4), TRANSPORTATION);
    listDataChild.put(listDataHeader.get(5), SPECIFICATIONS);
    listDataChild.put(listDataHeader.get(6), OPTIONALEQUIPMENT);
    listDataChild.put(listDataHeader.get(7), TROUBLESHOOTING);
    listDataChild.put(listDataHeader.get(8), SPECIALPROCEDURES);
}

}

private OnChildClickListener myListItemClicked =  new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
   Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
          Toast.LENGTH_SHORT).show();
   // Go to child #0 specific class.
   Intent child0Intent = new Intent(this, activity0.class);
   startActivity(Intent);

}

  return false;
}

Это должно было быть:

private OnChildClickListener myListItemClicked =  new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
   Toast.makeText(MainActivity.this, "Clicked On Child"+childPosition,
          Toast.LENGTH_SHORT).show();
   // Go to child #0 specific class.
   Intent child0Intent = new Intent(this, activity0.class);
   startActivity(Intent);

   return false;
  }
}

Вы использовали возврат вне метода...

Другие вопросы по тегам