小编Ber*_*sen的帖子

"对于类型create,方法setListAdapter(ArrayAdapter)未定义"

我是java和android的新手,所以我试图从android和数据库中找到有用的样本.我发现这个博客有一个项目:

http://saigeethamn.blogspot.com/2009/10/android-developer-tutorial-part-12.html

我运行该项目,它工作正常,但我正在尝试创建一个新项目来复制和粘贴代码,这不起作用:(

我在这一行遇到了问题:

this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

对于类型create,方法setListAdapter(ArrayAdapter)未定义

它看起来像是C#中的一个方法,但我可以在原始项目中找到它.

我在哪里弄错了?

java database android

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

错误:java.lang.NoClassDefFoundError Android

我正在按照本教程创建滑动选项卡.但我得到了上述错误.

我的gradle依赖sturucture

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:22.2.0'
}
Run Code Online (Sandbox Code Playgroud)

这是我的文件. MainActivity.java

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); //this line gives error
    tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); //this line gives error
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    PageAdapter pageAdapter …
Run Code Online (Sandbox Code Playgroud)

android gradle

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

Collections.sort没有排序任何东西

我正在尝试以简短的方式对String数组进行排序.我正在尝试使用Collections.sort,但我不明白为什么它不排序任何东西.码:

public static String[] FishNamesSorted;
.....
List<String> nameslist = new ArrayList<String>();
nameslist.toArray(FishNamesSorted);
Collections.sort(nameslist, String.CASE_INSENSITIVE_ORDER); <--- NOT WORKING

Collections.sort(nameslist, new Comparator<String>() { <--- NOT WORKING
    @Override
    public int compare(String p1, String p2) {
    if (p1 == null) {
        return 1;
    }
    if (p2 == null) {
        return -1;
    }
    return p1.compareToIgnoreCase(p2);
    }
});
Run Code Online (Sandbox Code Playgroud)

结果在两种情况下:

  • Poecilia Latipinna
  • Poecilia Reticulata
  • Notropis Chrosomus
  • Pseudomugil Gertrudae
  • ....

Whyyyy?

java sorting collections

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

如何在Java中附加到DataOutputStream?

我希望我的程序将URL地址(一次一个)保存到文件中.这些地址需要以UTF格式保存,以确保它们是正确的.

我的问题是文件一直被覆盖,而不是附加:

    DataOutputStream DOS = new DataOutputStream(new FileOutputStream(filen, true));
    Count = 0;
    if (LinkToCheck != null) {
    System.out.println(System.currentTimeMillis() + " SaveURL_ToRelatedURLS d "+LinkToCheck.Get_SelfRelationValue()+" vs "+Class_Controller.InterestBorder);
    if (LinkToCheck.Get_SelfRelationValue() > Class_Controller.InterestBorder) {
        DOS.writeUTF(LinkToCheck.Get_URL().toString() + "\n");
        Count++;
    }
    }
    DOS.close();
Run Code Online (Sandbox Code Playgroud)

此代码不会附加,所以我该如何追加它?

java append dataoutputstream

6
推荐指数
1
解决办法
2603
查看次数

Xamarin-如何淬灭或过滤应用程序输出?

在Xamarin中制作应用程序时,我正在使用“应用程序输出”进行调试。此日志通过数百条相同的消息而成为垃圾邮件,我不想看到。

如何淬灭或过滤某些消息以免出现在此日志中?

c# debugging xamarin

5
推荐指数
1
解决办法
633
查看次数

Java正则表达式不会删除点

我正在尝试删除“。” 在文本中,并将其替换为“。”。

我的代码:

System.out.println(TextHandler.class.toString() + " removeExcessiveSpaces E2 " + text);
while (text.contains("\\. \\.")) {
    text = text.replaceAll("\\. \\.", ".");
}
System.out.println(TextHandler.class.toString() + " removeExcessiveSpaces E3 " + text);
Run Code Online (Sandbox Code Playgroud)

文字输入:

"from the streets' fit but you know it. . this is just another case of female stopping play,. in an otherwise total result of a holiday. by m-uhjuly 04, 2006. . 8 . 42 . .. .... . . . . . . . . <script>//<![cdata["
Run Code Online (Sandbox Code Playgroud)

预期产量:

"from the streets' …
Run Code Online (Sandbox Code Playgroud)

java regex

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

无法处理异常?

Eclipse一直告诉我,我需要处理以下1行代码中的IOExceptions.

如果我为IOException添加一个catch它告诉我永远不会到达catch块,同时它仍然告诉我为同一行代码处理IOExceptions.

如果我改变ReadEvents而不是抛出异常,它将继续告诉我捕获异常.

public static void SetEventURL(String url, boolean streamingMode) throws Exception {
try {
    Thread eventReadingThread = new Thread(() -> ReadEvents(url, streamingMode));
} catch (IOException e1) {
} catch (Exception e1) {
} catch (Throwable e1) {
}
Run Code Online (Sandbox Code Playgroud)

为什么不能处理那条线

java exception

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

为什么我无法连接到 GitLab SSH 服务器?

为什么我无法连接到 GitLab SSH 服务器?我的本地设置有问题,但我找不到问题所在。

$ ssh -Tv -p 9292 gitlab@svn.faktab.net
OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to svn.faktab.net [xxx.xx.xxx.xxx] port 9292.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/bls/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/bls/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/bls/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file …
Run Code Online (Sandbox Code Playgroud)

git ssh rsa

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