gpt4 book ai didi

java - 当我尝试将有效的代码带入类中时,它会出现错误

转载 作者:行者123 更新时间:2023-12-01 10:48:59 24 4
gpt4 key购买 nike

这段代码工作正常,但是当我将它变成一个类并通过稍后实例化它来使用它时,我收到以下错误。我知道这是因为我缺乏android开发的基础。:

      import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class MainActivity extends AppCompatActivity {

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



AssetManager manager;
String line = null;
String[] bilgi = new String[20];
String[] ara = new String[20];
String[] hamle = new String[1000];



InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
int don = -1;
int don2 = -1;
int kontrol = 0;

try {
manager = getAssets();
is = manager.open("game366178.pgn");
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {

don++;
if (kontrol == 0) {
bilgi[don] = line;
} else {
ara = (line.split(" "));
for (int z = 0; z < ara.length; z++) {
don2++;
hamle[don2] = ara[z];
}
}

if (line.isEmpty()) {
kontrol = don;
}


}


TextView mytextview = (TextView) findViewById(R.id.showarray);
mytextview.setText(bilgi[8] + " kontrol equals to: " + kontrol);

} catch (IOException e1) {
Toast.makeText(getBaseContext(), "Problem!", Toast.LENGTH_LONG).show();
} finally {

try {
//if(reader != null)
// reader.close();
if (br != null)
br.close();
if (isr != null)
isr.close();
if (is != null)
is.close();
} catch (IOException ex) {
// dosomething
ex.printStackTrace();
}


}


}
}

But when I try to make a class out of it, we get an error =>

package chessactivesekizsatirvetekliarray.com.sekizsatirvetekliarray;

import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* Created by serhat on 01.12.2015.
*/
public class hamleArrayi extends AppCompatActivity {


AssetManager manager;
String line = null;
String[] bilgi = new String[20];
String[] ara = new String[20];
String[] hamle = new String[1000];



InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
int don = -1;
int don2 = -1;
int kontrol = 0;

try {
manager = getAssets();
is = manager.open("game366178.pgn");
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {

don++;
if (kontrol == 0) {
bilgi[don] = line;
} else {
ara = (line.split(" "));
for (int z = 0; z < ara.length; z++) {
don2++;
hamle[don2] = ara[z];
}
}

if (line.isEmpty()) {
kontrol = don;
}


}


// TextView mytextview = (TextView) findViewById(R.id.showarray);
//mytextview.setText(bilgi[8] + " kontrol equals to: " + kontrol);

}

catch (IOException e1)

{
Toast.makeText(getBaseContext(), "Problem!", Toast.LENGTH_LONG).show();
}

finally

{

try {
//if(reader != null)
// reader.close();
if (br != null)
br.close();
if (isr != null)
isr.close();
if (is != null)
is.close();
} catch (IOException ex) {

ex.printStackTrace();
}


}

}

当我清理项目以查看问题所在时,我得到 =>

  D:\Android_Dosyalar\Proje\SekizSatirVeTekliArray\app\src\main\java  
\chessactivesekizsatirvetekliarray\com\sekizsatirvetekliarray
\hamleArrayi.java
Error:(37, 5) error: illegal start of type
Error:(37, 8) error: ';' expected
Error:(38, 16) error: <identifier> expected
Error:(39, 11) error: <identifier> expected
Error:(40, 12) error: <identifier> expected
Error:(41, 11) error: <identifier> expected
Error:(42, 9) error: illegal start of type
Error:(42, 16) error: illegal start of type
Error:(42, 17) error: ')' expected
Error:(42, 21) error: ';' expected
Error:(42, 35) error: <identifier> expected
Error:(42, 37) error: ';' expected
Error:(68, 5) error: class, interface, or enum expected
Error:(72, 5) error: class, interface, or enum expected
Error:(83, 13) error: class, interface, or enum expected
Error:(85, 13) error: class, interface, or enum expected
Error:(87, 9) error: class, interface, or enum expected
Error:(90, 9) error: class, interface, or enum expected
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED

我复制并粘贴了代码。我有中级java但android新手。预先感谢您
问候

最佳答案

您创建的类没有方法。

 public class hamleArrayi extends AppCompatActivity   {


AssetManager manager;.....

关于java - 当我尝试将有效的代码带入类中时,它会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34031896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com