所以我试图从我的数据库mysql获取名称的列表视图,但是我一直收到错误消息,说我要在其中存储信息的数组为== null。这是主类的代码:
public class LVTut extends Activity{
static String result[] = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewdemo);
populateListView();
registerClickCallback();
}
private void populateListView() {
// TODO Auto-generated method stub
//Create list of items.
int i = 0;
String[] myItems = null;
while (result == null && i != 1){
result = ConnectMySQL.getName();
i++;
}
if (myItems == null){
String result[] = ConnectMySQL.getName();
myItems = result;
}
//Build Adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.da_item, myItems);
// Configure the list view.
ListView list = (ListView) findViewById(R.id.lvRanking);
list.setAdapter(adapter);
}
private void registerClickCallback() {
// TODO Auto-generated method stub
ListView list = (ListView) findViewById(R.id.lvRanking);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) {
// TODO Auto-generated method stub
TextView textView = (TextView) viewClicked;
String message = "You clicked # " + position
+ ", which is string: " + textView.getText().toString();
Toast.makeText(LVTut.this, message, Toast.LENGTH_LONG).show();
}
});
}
}
这是connectMySQL类
公共类ConnectMySQL扩展了活动{
static String host = "jdbc:mysql://localhost:3306/application";
static String username = "Kasea";
static String password = "*******";
String loginame, loginPass, displayname, gender, facebookId;
static String[] result;
public static void connection() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void addUser(String loginame, String loginPass, String displayname, String gender, String facebookId) {
connection();
try {
Connection connect = DriverManager.getConnection(host, username, password);
PreparedStatement statement = connect.prepareStatement("INSERT INTO users (loginame, loginPass, displayname, gender, facebookId) VALUES(?, ?, ?, ?, ?)");
statement.setString(1, loginame);
statement.setString(2, loginPass);
statement.setString(3, displayname);
statement.setString(4, gender);
statement.setString(5, facebookId);
statement.executeUpdate();
statement.close();
connect.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String[] getNameMale(){
connection();
try {
Connection connect = DriverManager.getConnection(host, username, password);
PreparedStatement statement = connect.prepareStatement("SELECT users.displayname, users.gender FROM users, picture WHERE users.id=picture.user_id && picture.gender like 'male' ORDER BY picture.finalsum DESC LIMIT 100");
ResultSet rs = statement.executeQuery();
ArrayList<String> list = new ArrayList<String>();
rs.first();
while (!rs.isAfterLast()){
list.add(rs.getString("displayname"));
rs.next();
}
result = new String[list.size()];
result = list.toArray(result);
statement.close();
connect.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*for(int i =0; i<result.length; i++){
System.out.println(result[i]);
}*/
return result;
}
public static String[] getNameFemale(){
connection();
try {
Connection connect = DriverManager.getConnection(host, username, password);
PreparedStatement statement = connect.prepareStatement("SELECT users.displayname, users.gender FROM users, picture WHERE users.id=picture.user_id && picture.gender like 'female' ORDER BY picture.finalsum DESC LIMIT 100");
ResultSet rs = statement.executeQuery();
ArrayList<String> list = new ArrayList<String>();
rs.first();
while (!rs.isAfterLast()){
list.add(rs.getString("displayname"));
rs.next();
}
result = new String[list.size()];
result = list.toArray(result);
statement.close();
connect.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*for(int i =0; i<result.length; i++){
System.out.println(result[i]);
}*/
return result;
}
public static String[] getName(){
connection();
try {
Connection connect = DriverManager.getConnection(host, username, password);
PreparedStatement statement = connect.prepareStatement("SELECT users.displayname, users.gender FROM users, picture WHERE users.id=picture.user_id ORDER BY picture.finalsum DESC LIMIT 100");
ResultSet rs = statement.executeQuery();
ArrayList<String> list = new ArrayList<String>();
rs.first();
while (!rs.isAfterLast()){
list.add(rs.getString("displayname"));
Log.d("AWESOME APP", "rs is: " + rs.getString("displayname"));
rs.next();
}
result = new String[list.size()];
result = list.toArray(result);
statement.close();
connect.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*for(int i =0; i<result.length; i++){
System.out.println(result[i]);
}*/
return result;
}
public static void InsertImage(String user_id, String gender, Blob image, String filePath) {
connection();
try {
Connection connect = DriverManager.getConnection(host, username, password);
PreparedStatement statement = connect.prepareStatement("INSERT INTO picture (user_id, gender, image) VALUES(?, ?, ?)");
statement.setString(2, user_id);
statement.setString(3, gender);
InputStream inputStream = new FileInputStream(new File(filePath));
statement.setBlob(8, image);
statement.executeUpdate();
statement.close();
connect.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我得到的日志猫:
08-06 06:41:52.677: D/dalvikvm(1968): GC_FOR_ALLOC freed 69K, 8% free 2562K/2760K, paused 59ms, total 60ms
08-06 06:41:52.717: I/dalvikvm-heap(1968): Grow heap (frag case) to 3.230MB for 635808-byte allocation
08-06 06:41:52.817: D/dalvikvm(1968): GC_FOR_ALLOC freed <1K, 6% free 3182K/3384K, paused 94ms, total 94ms
08-06 06:41:53.167: D/dalvikvm(1968): GC_FOR_ALLOC freed 230K, 10% free 3466K/3824K, paused 14ms, total 14ms
08-06 06:41:53.517: W/dalvikvm(1968): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)
08-06 06:41:53.517: I/dalvikvm(1968): Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom
08-06 06:41:53.517: W/dalvikvm(1968): VFY: unable to resolve virtual method 14719: Ljavax/naming/Reference;.get (Ljava/lang/String;)Ljavax/naming/RefAddr;
08-06 06:41:53.527: D/dalvikvm(1968): VFY: replacing opcode 0x6e at 0x0004
08-06 06:41:53.527: W/dalvikvm(1968): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)
08-06 06:41:53.527: E/dalvikvm(1968): Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo
08-06 06:41:53.527: W/dalvikvm(1968): VFY: unable to resolve new-instance 1343 (Ljavax/naming/StringRefAddr;) in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;
08-06 06:41:53.527: D/dalvikvm(1968): VFY: replacing opcode 0x22 at 0x0006
08-06 06:41:53.537: D/dalvikvm(1968): DexOpt: unable to opt direct call 0x3981 at 0x14 in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;.storeTo
08-06 06:41:53.747: D/dalvikvm(1968): GC_FOR_ALLOC freed 188K, 8% free 3792K/4108K, paused 15ms, total 15ms
08-06 06:41:53.757: I/dalvikvm(1968): Could not find method java.lang.management.ManagementFactory.getThreadMXBean, referenced from method com.mysql.jdbc.MysqlIO.appendDeadlockStatusInformation
08-06 06:41:53.767: W/dalvikvm(1968): VFY: unable to resolve static method 14004: Ljava/lang/management/ManagementFactory;.getThreadMXBean ()Ljava/lang/management/ThreadMXBean;
08-06 06:41:53.767: D/dalvikvm(1968): VFY: replacing opcode 0x71 at 0x0079
08-06 06:41:53.877: W/System.err(1968): com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
08-06 06:41:53.877: W/System.err(1968): at java.lang.reflect.Constructor.constructNative(Native Method)
08-06 06:41:53.887: W/System.err(1968): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-06 06:41:53.887: W/System.err(1968): at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
08-06 06:41:53.887: W/System.err(1968): at com.mysql.jdbc.Util.getInstance(Util.java:383)
08-06 06:41:53.887: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1023)
08-06 06:41:53.887: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
08-06 06:41:53.887: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
08-06 06:41:53.887: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2590)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
08-06 06:41:53.897: W/System.err(1968): at java.lang.reflect.Constructor.constructNative(Native Method)
08-06 06:41:53.897: W/System.err(1968): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
08-06 06:41:53.897: W/System.err(1968): at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
08-06 06:41:53.907: W/System.err(1968): at java.sql.DriverManager.getConnection(DriverManager.java:179)
08-06 06:41:53.907: W/System.err(1968): at java.sql.DriverManager.getConnection(DriverManager.java:213)
08-06 06:41:53.907: W/System.err(1968): at alexxela.xela.kasea.ConnectMySQL.getName(ConnectMySQL.java:104)
08-06 06:41:53.907: W/System.err(1968): at alexxela.xela.kasea.LVTut.populateListView(LVTut.java:32)
08-06 06:41:53.907: W/System.err(1968): at alexxela.xela.kasea.LVTut.onCreate(LVTut.java:21)
08-06 06:41:53.907: W/System.err(1968): at android.app.Activity.performCreate(Activity.java:5133)
08-06 06:41:53.907: W/System.err(1968): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-06 06:41:53.907: W/System.err(1968): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-06 06:41:53.917: W/System.err(1968): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-06 06:41:53.917: W/System.err(1968): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-06 06:41:53.917: W/System.err(1968): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-06 06:41:53.917: W/System.err(1968): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 06:41:53.917: W/System.err(1968): at android.os.Looper.loop(Looper.java:137)
08-06 06:41:53.917: W/System.err(1968): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-06 06:41:53.917: W/System.err(1968): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 06:41:53.917: W/System.err(1968): at java.lang.reflect.Method.invoke(Method.java:525)
08-06 06:41:53.917: W/System.err(1968): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-06 06:41:53.927: W/System.err(1968): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-06 06:41:53.927: W/System.err(1968): at dalvik.system.NativeStart.main(Native Method)
08-06 06:41:53.927: W/System.err(1968): Caused by: android.os.NetworkOnMainThreadException
08-06 06:41:53.927: W/System.err(1968): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
08-06 06:41:53.927: W/System.err(1968): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-06 06:41:53.927: W/System.err(1968): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-06 06:41:53.937: W/System.err(1968): at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-06 06:41:53.937: W/System.err(1968): at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:250)
08-06 06:41:53.937: W/System.err(1968): at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
08-06 06:41:53.937: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2504)
08-06 06:41:53.937: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
08-06 06:41:53.937: W/System.err(1968): ... 27 more
08-06 06:41:53.957: W/System.err(1968): com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
08-06 06:41:53.957: W/System.err(1968): at java.lang.reflect.Constructor.constructNative(Native Method)
08-06 06:41:53.957: W/System.err(1968): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-06 06:41:53.957: W/System.err(1968): at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
08-06 06:41:53.957: W/System.err(1968): at com.mysql.jdbc.Util.getInstance(Util.java:383)
08-06 06:41:53.957: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1023)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2590)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
08-06 06:41:53.967: W/System.err(1968): at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
08-06 06:41:53.967: W/System.err(1968): at java.lang.reflect.Constructor.constructNative(Native Method)
08-06 06:41:53.977: W/System.err(1968): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-06 06:41:53.977: W/System.err(1968): at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
08-06 06:41:53.977: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
08-06 06:41:53.977: W/System.err(1968): at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
08-06 06:41:53.977: W/System.err(1968): at java.sql.DriverManager.getConnection(DriverManager.java:179)
08-06 06:41:53.977: W/System.err(1968): at java.sql.DriverManager.getConnection(DriverManager.java:213)
08-06 06:41:53.977: W/System.err(1968): at alexxela.xela.kasea.ConnectMySQL.getName(ConnectMySQL.java:104)
08-06 06:41:53.977: W/System.err(1968): at alexxela.xela.kasea.LVTut.populateListView(LVTut.java:36)
08-06 06:41:53.987: W/System.err(1968): at alexxela.xela.kasea.LVTut.onCreate(LVTut.java:21)
08-06 06:41:53.987: W/System.err(1968): at android.app.Activity.performCreate(Activity.java:5133)
08-06 06:41:53.987: W/System.err(1968): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-06 06:41:53.987: W/System.err(1968): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-06 06:41:53.987: W/System.err(1968): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-06 06:41:53.987: W/System.err(1968): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-06 06:41:53.987: W/System.err(1968): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-06 06:41:53.987: W/System.err(1968): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 06:41:53.987: W/System.err(1968): at android.os.Looper.loop(Looper.java:137)
08-06 06:41:53.997: W/System.err(1968): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-06 06:41:53.997: W/System.err(1968): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 06:41:53.997: W/System.err(1968): at java.lang.reflect.Method.invoke(Method.java:525)
08-06 06:41:53.997: W/System.err(1968): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-06 06:41:53.997: W/System.err(1968): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-06 06:41:53.997: W/System.err(1968): at dalvik.system.NativeStart.main(Native Method)
08-06 06:41:53.997: W/System.err(1968): Caused by: android.os.NetworkOnMainThreadException
08-06 06:41:54.007: W/System.err(1968): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
08-06 06:41:54.007: W/System.err(1968): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-06 06:41:54.007: W/System.err(1968): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-06 06:41:54.007: W/System.err(1968): at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-06 06:41:54.007: W/System.err(1968): at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:250)
08-06 06:41:54.007: W/System.err(1968): at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
08-06 06:41:54.007: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2504)
08-06 06:41:54.007: W/System.err(1968): at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
08-06 06:41:54.017: W/System.err(1968): ... 27 more
08-06 06:41:54.017: D/AndroidRuntime(1968): Shutting down VM
08-06 06:41:54.017: W/dalvikvm(1968): threadid=1: thread exiting with uncaught exception (group=0xb2f55648)
08-06 06:41:54.027: E/AndroidRuntime(1968): FATAL EXCEPTION: main
08-06 06:41:54.027: E/AndroidRuntime(1968): java.lang.RuntimeException: Unable to start activity ComponentInfo{alexxela.xela.kasea/alexxela.xela.kasea.LVTut}: java.lang.NullPointerException: storage == null
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.os.Looper.loop(Looper.java:137)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-06 06:41:54.027: E/AndroidRuntime(1968): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 06:41:54.027: E/AndroidRuntime(1968): at java.lang.reflect.Method.invoke(Method.java:525)
08-06 06:41:54.027: E/AndroidRuntime(1968): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-06 06:41:54.027: E/AndroidRuntime(1968): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-06 06:41:54.027: E/AndroidRuntime(1968): at dalvik.system.NativeStart.main(Native Method)
08-06 06:41:54.027: E/AndroidRuntime(1968): Caused by: java.lang.NullPointerException: storage == null
08-06 06:41:54.027: E/AndroidRuntime(1968): at java.util.Arrays$ArrayList.<init>(Arrays.java:38)
08-06 06:41:54.027: E/AndroidRuntime(1968): at java.util.Arrays.asList(Arrays.java:154)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128)
08-06 06:41:54.027: E/AndroidRuntime(1968): at alexxela.xela.kasea.LVTut.populateListView(LVTut.java:41)
08-06 06:41:54.027: E/AndroidRuntime(1968): at alexxela.xela.kasea.LVTut.onCreate(LVTut.java:21)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.Activity.performCreate(Activity.java:5133)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-06 06:41:54.027: E/AndroidRuntime(1968): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-06 06:41:54.027: E/AndroidRuntime(1968): ... 11 more
08-06 06:41:57.337: I/Process(1968): Sending signal. PID: 1968 SIG: 9
我知道问题是result []为=为null,但是我不知道为什么,我的意思是我的代码不应该将数据库中的信息添加到其中吗?我知道mysql查询有效,我已经测试过了,结果理论上应该可行,不是吗?
另外,如果这不是一个“好”问题,请告诉我为什么:s我已经问了很多不好的问题:P
编辑:更新了我所做的代码,并且我还编辑了logcat
最佳答案
替换您的oncreate方法
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewdemo);
result= getName();
populateListView();
registerClickCallback();
}
将getname的返回值分配给结果变量。