小编Col*_*lin的帖子

如何修复InstantiationException,无法实例化Fragment?

这是我的第一篇文章,所以我提前道歉...

我正在尝试编译一个简单的Drawer示例/练习应用程序.但是,当我点击列表视图中的项目时,它会崩溃.Logcat说它无法从android.app.Fragment实例化.我也试过使用android.support.v4库 - 假设我正确实现了它,这是可疑的 - 具有相同的结果.坦率地说,我不确定区别是什么.我完全难过了.请帮忙!

主要活动:

package pac.gazette;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    private String[] fragmentNames;
    private String[] fragmentAddresses;

    private DrawerLayout drawer;
    private ListView drawerList;

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

        fragmentNames = getResources().getStringArray(R.array.fragment_names);
        fragmentAddresses = getResources().getStringArray(
                R.array.fragment_options);
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerList = (ListView) findViewById(R.id.left_drawer);
        drawerList.setAdapter(new ArrayAdapter<String>(this,
                R.layout.drawer_list, fragmentNames));
        drawerList.setOnItemClickListener (new CustomClickListener());

    } …
Run Code Online (Sandbox Code Playgroud)

android instantiationexception android-fragments fragmenttransaction navigation-drawer

2
推荐指数
1
解决办法
1万
查看次数

与IntelliJ等效的Eclipse格式代码?

名字说的.IntelliJ中是否存在Ctrl-Shift-F的模拟?我搜索过,没找到.非常感谢.

keyboard-shortcuts intellij-idea

2
推荐指数
1
解决办法
768
查看次数