Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Studio、Sql、TextView_Android_Sql_Textview - Fatal编程技术网

Android Studio、Sql、TextView

Android Studio、Sql、TextView,android,sql,textview,Android,Sql,Textview,我正在发布我的帖子 在测试并添加建议的修改之后,我仍然无法让代码正常工作。每次我重新开始跳芭蕾舞,然后尝试添加我的代码,它就会失败 如果你能纠正我或指出我没有抓住要点的地方,那就太好了 这很好: 在MyActivity.java中有一个可单击的按钮 /** Called when the user clicks the Send button */ public void goExample(View view) { Intent intent = new Intent(this, Ex

我正在发布我的帖子

在测试并添加建议的修改之后,我仍然无法让代码正常工作。每次我重新开始跳芭蕾舞,然后尝试添加我的代码,它就会失败

如果你能纠正我或指出我没有抓住要点的地方,那就太好了

这很好:

在MyActivity.java中有一个可单击的按钮

/** Called when the user clicks the Send button */
public void goExample(View view) {
    Intent intent = new Intent(this, Example.class);
    startActivity(intent);
}
这带来了课堂示例:

 public class Example extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView total = (TextView)findViewById(R.id.total);
            setContentView(R.layout.example);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu, menu);
            return true;
        }}
以及它的view example.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Example">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+android:id/total"
        android:layout_weight="1" />

</RelativeLayout>
然后,它惨遭失败,出现以下错误:

6715-6715/tab.sqltesting.com.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{tab.sqltesting.com.myapplication/tab.sqltesting.com.myapplication.Example}: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT * FROM joueurs
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
            at android.app.ActivityThread.access$600(ActivityThread.java:140)
            at dalvik.system.NativeStart.main(Native Method)
...
     Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT * FROM joueurs
            at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
            at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58)
老实说,我不知道该怎么办,任何帮助都将不胜感激


谢谢

为什么不反向浏览两行代码呢

与此相反:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView total = (TextView)findViewById(R.id.total);
        setContentView(R.layout.example);
    }
这样做:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.example);
        TextView total = (TextView)findViewById(R.id.total);
    }

提示:您应该首先设置内容视图,然后声明变量。

在您的类示例中。您应该在setcontentview之后声明小部件

public class Example extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.example);
            TextView total = (TextView)findViewById(R.id.total);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu, menu);
            return true;
        }}
public class Example extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.example);
            TextView total = (TextView)findViewById(R.id.total);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu, menu);
            return true;
        }}