我有一个带有一个Activity的应用程序和多个加载某些子视图的片段和一个用于显示HTML文件的WebView。
WebViews位于片段布局中。现在,当MainActivity扩展 AppCompatActivity 时,应用程序会长按(突出显示文本)而崩溃,但使用 ActionBarActivity 应用程序适用,并显示上下文菜单。
我不知道为什么会这样,但我会感激任何指示。
这是我得到的日志:
02-08 16:48:53.290 30263-30263/com.amr.demo A/chromium: [FATAL:jni_android.cc(236)] Please include Java exception stack in crash report
崩溃的其余部分是(在问题中添加太久了)here
这是片段 Java文件:
package fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.ineqe.able.library.AbleWebView;
import com.ineqe.able.library.MainActivity;
import com.ineqe.able.library.MyApplication;
import com.ineqe.able.library.R;
public class NewsItemFrag extends Fragment {
private String video_id;
private SharedPreferences sp2;
private Intent mainmenu;
private AbleWebView wv;
private SharedPreferences sp3;
private String link;
private String header;
private SharedPreferences sharedpreferences;
private int groupPosition;
@Override
public void onResume() {
super.onResume();
sp3 = getActivity().getSharedPreferences("textSize", Context.MODE_PRIVATE);
int size = sp3.getInt("textSize", 17);
WebSettings webSettings = wv.getSettings();
webSettings.setDefaultFontSize(size);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int i = item.getItemId();
if (i == R.id.share) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, link);
startActivity(Intent.createChooser(intent, "Share with"));
return true;
} else {
return false;
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.newsitem, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_content, container, false);
wv = (AbleWebView) view.findViewById(R.id.webview);
wv.setLongClickable(false);
Bundle args = getArguments();
String image = args.getString("image", "");
String web = args.getString("web", "");
groupPosition = args.getInt("gposition", 1);
LinearLayout Musicplayout = (LinearLayout) view.findViewById(R.id.musicp);
RelativeLayout Rlayout = (RelativeLayout) view.findViewById(R.id.buttons);
Musicplayout.setVisibility(View.GONE);
Rlayout.setVisibility(View.GONE);
link = args.getString("link", "");
header = args.getString("header_image", "");
wv.loadDataWithBaseURL("file:///android_asset/", web, "text/html", "charset=UTF-8", null);
ImageButton img = (ImageButton) view.findViewById(R.id.topimage);
sharedpreferences = getActivity().getSharedPreferences("sharedpref", Context.MODE_PRIVATE);
img.setImageDrawable(ContextCompat.getDrawable(getActivity(), getResources().getIdentifier("@drawable/" + header, null, getActivity().getPackageName())));
WebSettings w = wv.getSettings();
w.setPluginState(WebSettings.PluginState.ON);
w.setJavaScriptEnabled(true);
setHasOptionsMenu(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
view.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
MainActivity.position = groupPosition + 1;
sharedpreferences.edit().putBoolean("back", true).apply();
mainmenu = new Intent(getActivity(), ((MyApplication) getActivity().getApplication()).getMainActivity());
mainmenu.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainmenu);
getActivity().finish();
}
return true;
}
});
return view;
}
}
答案 0 :(得分:0)
崩溃发生是因为我从错误的地址得到了什么。我仍在试图弄清楚该参考是什么。