user3463989
user3463989

Reputation: 225

Code not working in app

An error is showing up in line 24 Class is a Raw type.References to generic Type Class<t> should be parametrised. 24th line is the one starting in try in block. Earlier it was working fine but now I have this error showing up because of which I cannot run it.

package com.example.testing;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Menu extends ListActivity {

    String classes[]={"MainActivity","TextPlay","example2","example3","example4","example5"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classes));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        String cheese=classes[position];
        try {
             Class ourClass = Class.forName("com.example.testing."+ cheese);
             Intent ourIntent=new Intent(Menu.this , ourClass);
             startActivity(ourIntent);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

Error is :

 `Class is a Raw type.References to generic Type Class<t> should be parametrised`

Upvotes: 0

Views: 51

Answers (1)

sabadow
sabadow

Reputation: 5153

I think this isn't an error, it should be a warning.

If you see the Class javadoc file you could see that the forNamemethod returns a Class<?>

So you can ignore the warning using the @SuppressWarning annotation or you can provide the the type of the generic:

Class<?> ourClass = Class.forName("com.example.testing."+ cheese);

Hope it helps.

Upvotes: 1

Related Questions