小编And*_*ler的帖子

为什么我在RecyclerView上获得空引用

我试图在我的片段中使用RecyclerView.它显示第一个选项卡正常,但是当我滑动到第二个选项卡然后回到第一个选项卡时,我收到以下错误:

java.lang.NullPointerException:尝试在空对象引用上调用虚方法'void android.support.v7.widget.RecyclerView $ LayoutManager.stopSmoothScroller()'

有谁知道为什么我会收到这个错误?似乎在片段切换之前有一个我失踪的电话,但我无法理解.

用于片段的寻呼机适配器:

public class PagerAdapter extends FragmentPagerAdapter {

    private final String[] TITLES = {"Header 0", "Header 1" };

    public PagerAdapter(FragmentManager fm){
        super(fm);
    }

    @Override
    public CharSequence getPageTitle(int position){
        return TITLES[position];
    }

    @Override
    public int getCount() {
        return TITLES.length;
    }

    @Override
    public Fragment getItem(int position){
        switch(position){
            case 0:
                return new FragmentOne();
            case 1:
                return new FragmentTwo();
            default:
                return new FragmentOne();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

FragmentOne&FragmentTwo使用我创建的样板类:

public class FragmentOne extends Base {
    ... code for displaying content in …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments

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

如何使用JSONObject构建JSON时嵌套对象

我正在尝试为POST请求编码此字符串.任何人都可以告诉我如何编码

{"jsonrpc": "2.0", "method": "Files.GetSources", "params":{"media":"music"}, "id": 1}
Run Code Online (Sandbox Code Playgroud)

到目前为止我有

JSONOjbect obj = new JSONObject();
obj.put("jsonrpc", "2.0");
obj.put("method", "Files.GetSources");
Run Code Online (Sandbox Code Playgroud)

但是我不知道怎么放其余的 - 有人可以帮忙吗?

java android json

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

如何制作php文件下载?

所以我在我的测试网站上的PHP脚本中有这个:

$file="clip.mp4";
$fake="clip_testing.mp4";
$fsize = filesize($file);
header("Content-Length: $fsize");
header("Content-Disposition: attachment; filename=$fake");
header("Content Type: application/download");

set_time_limit(0);
$fs = @fopen($file,"rb");

while(!feof($fs))

{
    print(@fread($fs, 1024*8));
    ob_flush();
    flush();
}
Run Code Online (Sandbox Code Playgroud)

当我在链接中使用它并下载文件时,我的文件的前7个字节被更改..因此我必须编辑程序才能使用它.我添加了一张图片,以便在我说前7个字节发生变化时更清楚地说明我在说什么.我错过了标题吗?谁能帮我?对照

编辑:如果你们因为它的大小而在查看图片时遇到问题,请在没有格式的新标签中查看图像,这样它就是原始尺寸.

php download

4
推荐指数
1
解决办法
1006
查看次数

WinRT的TcpListener类在哪里?

我试图按照此页面上给出的示例:

http://www.codeproject.com/Articles/137979/Simple-HTTP-Server-in-C

但我正在为Metro/WinRT商店应用程序开发.当我尝试使用它所说的许多类时,会丢失很多类.我知道这是因为他们决定在迁移时摆脱很多库...但是有谁知道我怎么能够引用丢失的类?缺少TcpListener类.或者有没有人知道我可以参考替换丢失的库的免费库?

c# microsoft-metro windows-runtime

3
推荐指数
1
解决办法
834
查看次数

为什么我的listview适配器在新视图上没有显示正确的布局?

我有一个自定义的光标适配器,它基于android中的MMS和SMS数据库.代码如下所示:

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {

    Message m = Message.getMessage(context, cursor); // gets message from cursor
    int t = m.getType(); // this gets the type of message it is .. 2 = recv, 1 = sent

    switch(t){
    case Message.MMS_IN: // 128
        return mInflater.inflate(R.layout.messagelist_item_recv, parent, false);
    case Message.MMS_OUT: // 132
        return mInflater.inflate(R.layout.messagelist_item_sent, parent, false);
    case Message.SMS_IN: // 2
        return mInflater.inflate(R.layout.messagelist_item_recv, parent, false);
    case Message.SMS_OUT: // 1
        return mInflater.inflate(R.layout.messagelist_item_sent, parent, false);
    default:
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

的 …

java android

0
推荐指数
1
解决办法
1736
查看次数

为什么我的片段中的活动上下文为空?

我正在尝试创建一个样板片段。当我尝试设置 RecyclerView 的 LayoutManager 时,我不断收到空引用错误:

尝试在空对象引用上调用虚拟方法“void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)”

以下是我调用以获取错误的顺序:

主类:

public class PagerAdapter extends FragmentPagerAdapter {
    ...
    @Override
    public Fragment getItem(int position){
        switch(position){
            default:
                return new WhatsNew();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

WhatsNew.class:

public class WhatsNew extends Base {

    private LayoutInflater mInflater;
    private Handler mHandler = new Handler();

    private RecyclerView.LayoutManager mLayoutManager;

    @Override
    public void init() {
        mInflater = LayoutInflater.from(mContext);
        mLayoutManager = new LinearLayoutManager(mContext);
        mDataView.setLayoutManager(mLayoutManager);  //<-- Where the null reference is
    }

    @Override
    public void doWork() {

        WhatsNewAdapter mAdapter = new WhatsNewAdapter();
        mDataView.setAdapter(mAdapter);
        ... …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments

0
推荐指数
1
解决办法
862
查看次数