16

i was having working code with earlier version of java 8 which i was using to get unique values from list but since i upgraded to JDK 66 its giving me an error

Type mismatch: cannot convert from List<Object> to List<String>

List<String> instList = new ArrayList<String>();

while (res.next()) {
    instList.add(res.getString("INST").toString());
}           

List<String> instListF = instList.stream().distinct().collect(Collectors.toList());

Where res is resultset i am getting from database, not sure what is wrong any idea?


How to handle Recyclerview list item click event

I am working with recyclerview but I am trying to intent to next activity but there is not setonlistitem method can any one tell how to redirect to next activity on click of list item,following is my snippet code can any one help me with that

public class SubcategoryActivity extends AppCompatActivity{

    private Toolbar mToolbar;

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


        mToolbar = (Toolbar) findViewById(R.id.toolbarsubcategory_list);
        setSupportActionBar(mToolbar);
        setTitle(getString(R.string.app_name));
        mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewsubcategory);


        ItemData itemsData[] = { new ItemData("Help",R.drawable.logo),
                new ItemData("Delete",R.drawable.logo),
                new ItemData("Cloud",R.drawable.logo),
                new ItemData("Favorite",R.drawable.logo),
                new ItemData("Like",R.drawable.logo),
                new ItemData("Rating",R.drawable.logo)};


        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        MyAdapter mAdapter = new MyAdapter(itemsData);
        recyclerView.setAdapter(mAdapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());




    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }
}
4

4 に答える 4

4

次の完全な例を確認しました。

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.stream.Collectors;
import java.util.List;
import java.util.ArrayList;

public class Test { 
    public List<String> test(ResultSet res) throws SQLException {
        List<String> instList = new ArrayList<String>();

        while (res.next()) {
            instList.add(res.getString("INST").toString());
        }           

        List<String> instListF = instList.stream().distinct().collect(Collectors.toList());
        return instListF;
    }
}

javac 8u25、8u40、8u60、8u71 で完全にコンパイルされます (8u71 は 8u66 のセキュリティ更新プログラムであるため、本質的に同じであることに注意してください)。プロジェクトをクリーンアップして、最初から再構築してみてください。

于 2016-01-25T10:47:41.687 に答える