我正在从菜单开始活动:
if (id == R.id.action_debug_test) {
Intent i = new Intent(this, RecycleActivity.class);
startActivity(i);
//return true;
}
这是崩溃它的活动:
package zeman.diktafonmev;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class RecycleActivity extends AppCompatActivity {
private List<Movie> movieList = new ArrayList<>();
private RecyclerView recyclerView;
private MoviesAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
/*
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
*/
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mAdapter = new MoviesAdapter(movieList);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new ClickListener() {
@Override
public void onClick(View view, int position) {
Movie movie = movieList.get(position);
Toast.makeText(getApplicationContext(), movie.getTitle() + " is selected!", Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClick(View view, int position) {
}
}));
prepareMovieData();
}
private void prepareMovieData() {
String end = ".mp3";
String end2 = ".3gp";
File myMp3Dir = new File(Environment.getExternalStorageDirectory() + "/ZemanRecording/");
ArrayList songs = new ArrayList();
final File[] fileList = myMp3Dir.listFiles();
if (fileList == null)
return;
for (File f : fileList) {
if (!f.isDirectory()) //if file is browsing not directory
{
if (f.getName().toLowerCase().contains(end)) //if file with end is .mp3 is add to arraylist
songs.add(f.getName());
if(f.getName().toLowerCase().contains(end2))
songs.add(f.getName());
Movie movie = new Movie(f.getName(), Boolean.toString(f.canRead()), "2015");
movieList.add(movie);
}
}
mAdapter.notifyDataSetChanged();
}
public interface ClickListener {
void onClick(View view, int position);
void onLongClick(View view, int position);
}
public static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
private GestureDetector gestureDetector;
private RecycleActivity.ClickListener clickListener;
public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final RecycleActivity.ClickListener clickListener) {
this.clickListener = clickListener;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null) {
clickListener.onLongClick(child, recyclerView.getChildPosition(child));
}
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
clickListener.onClick(child, rv.getChildPosition(child));
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
}
}
基本上我正在使用this。
我可以单独运行它,但我只复制它并重命名其中一些部分才能正常工作,因为我已经有activity_main
,所以我将该项目中的一个重命名为{{1} }。
我已将其添加到activity_recycle.xml
,我的应用确实拥有所需的权限。
AndroidManifest.xml
content_main.xml
ERROR
03-17 08:20:01.584 7290-7290/zeman.diktafonmev E/AndroidRuntime: FATAL EXCEPTION: main
Process: zeman.diktafonmev, PID: 7290
java.lang.RuntimeException: Unable to start activity ComponentInfo{zeman.diktafonmev/zeman.diktafonmev.RecycleActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f04001e
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04001e
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2598)
at android.content.res.Resources.getLayout(Resources.java:1049)
at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at zeman.diktafonmev.RecycleActivity.onCreate(RecycleActivity.java:27)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这就是我的项目的样子 - (土地)可能会影响它吗?我也尝试在横向模式下启动活动,它仍然崩溃。
答案 0 :(得分:0)
您是否有此布局文件(R.layout.content_main)
?
您在第27行(android.content.res.Resources$NotFoundException:
方法中)收到此错误onCreate()
。
如果你有这个文件,那么在那里设置xml的方式可能存在一些错误。 如果有,请分享该xml文件。
答案 1 :(得分:0)
您是否在RecycleActivity中导入了R?我没有在进口的任何地方看到zeman.diktafonmev.R。
您也可以尝试清理和重建项目。
答案 2 :(得分:-1)
从XML
中删除行tools:showIn