我正在尝试构建一个音乐播放器应用程序。我正在尝试从虚拟设备的SD卡中显示歌曲名称。
public class MainActivity extends AppCompatActivity {
private static final String TAG="message";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG,"onCreate STarted");
Log.i(TAG,"listAdapterTo be Initilized");
final Cursor c = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,new String[]{MediaStore.Audio.Media.DISPLAY_NAME},null,null,null);
ListAdapter songAdapter = new CustomCursorAdapter(this,c);
Log.i(TAG,"ListAdapterSuccessfull");
ListView lv= (ListView) findViewById(R.id.listView);
lv.setAdapter(songAdapter);
Log.i(TAG,"success");
}
public class CustomCursorAdapter extends CursorAdapter{
private static final String TAG="message";
LayoutInflater mInflater;
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Log.i(TAG,"newView");
View customView = mInflater.inflate(R.layout.custom_row,parent,false);
return customView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
Log.i(TAG,"BindVIew");
TextView textView = (TextView) view.findViewById(R.id.tv);
textView.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
}
public CustomCursorAdapter(Context context, Cursor c, LayoutInflater mInflater) {
super(context, c);
this.mInflater = mInflater;
}
}
}
应用程序在运行时崩溃,cursorAdapter
甚至没有被调用。
信息:Gradle任务[:app:incrementalDebugSupportDex] :应用:buildInfoDebugLoader :app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE :应用:compileDebugJavaWithJavac /home/krozen/AndroidStudioProjects/CorverArtEx/app/src/main/java/com/example/krozen/corverartex/MainActivity.java 错误:(29,35)错误:类中的构造函数CustomCursorAdapter CustomCursorAdapter无法应用于给定类型;需要: Context,Cursor,LayoutInflater发现:MainActivity,游标原因: 实际和正式的参数列表长度不同注意: /home/krozen/AndroidStudioProjects/CorverArtEx/app/src/main/java/com/example/krozen/corverartex/CustomCursorAdapter.java 使用或覆盖已弃用的API。注意:重新编译 -Xlint:弃用细节。在0.732秒内完成2个类的增量编译。 :app:compileDebugJavaWithJavac FAILED 错误:任务':app:compileDebugJavaWithJavac'执行失败。
编译失败;请参阅编译器错误输出以获取详细信信息:BUILD FAILED信息:总时间:3.519秒 信息:2错误信息:0警告信息:请参阅完整 控制台输出