原Activity代码有点长……我只把监听器复过来:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Intent intent = new Intent();
intent.putExtra("choose", position);
intent.setClass(IntroductionActivity.this, detailActivity.class);
IntroductionActivity.this.startActivity(intent);
System.out.println("positon---->"+position);
}运行程序的时候发现logcat中有输出position,所以应该不是这个activity的问题了吧?
另一个activity源代码如下:package mars.product;import java.io.*;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class detailActivity extends ListActivity {
private TextView detailview = null;
private Button backbutton = null;
private Button linkbutton = null;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState){
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.detail); Intent intent = getIntent();
//注意getIntExtra的返回值是int,后面参数int defaultvalue 干嘛的不知道……
i = intent.getIntExtra("choose", 0);
System.out.println("i------>"+i);
detailview = (TextView)findViewById(R.id.detailview);
//读入txt资源,创建输入流
InputStream is = getResources().openRawResource(R.raw.introduction);
//创建字符创存放缓存
byte[] buffer = new byte[1024];
int rd = 0;
//新建输出流
ByteArrayOutputStream output = new ByteArrayOutputStream();
//读取文本文件到缓存中
try{
while((rd = is.read(buffer)) != -1){
output.write(buffer, 0, rd);
}
//简体中文编码GBK,繁体big5?
String temp = new String(output.toByteArray(),"GBK");
//将获得字符串拆开,截取各段内容赋给string[]数组---trim去掉两边空白字符后的字符串---split分割函数
String[] detail = temp.trim().split("#");
detailview.setText(detail[i]);
//关闭输出流
output.close();
} catch (IOException e){
e.printStackTrace();
}
backbutton = (Button)findViewById(R.id.backbutton);
backbutton.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
linkbutton = (Button)findViewById(R.id.linkbutton);
linkbutton.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(detailActivity.this, linkActivity.class);
intent.putExtra("i", i);//直接传输网址的数组位置,不用+1
detailActivity.this.startActivity(intent);
}
});
}
}这个activity的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/detailview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dp"
/>
<Button
android:id="@+id/linkbutton"
android:layout_below="@id/detailview"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/linkbutton"
android:paddingTop="10dp"
/>
<Button
android:id="@+id/backbutton"
android:padding="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/backbutton"
/>
</RelativeLayout>请问是出现什么问题了……Manifest里面也注册了啊!
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Intent intent = new Intent();
intent.putExtra("choose", position);
intent.setClass(IntroductionActivity.this, detailActivity.class);
IntroductionActivity.this.startActivity(intent);
System.out.println("positon---->"+position);
}运行程序的时候发现logcat中有输出position,所以应该不是这个activity的问题了吧?
另一个activity源代码如下:package mars.product;import java.io.*;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class detailActivity extends ListActivity {
private TextView detailview = null;
private Button backbutton = null;
private Button linkbutton = null;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState){
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.detail); Intent intent = getIntent();
//注意getIntExtra的返回值是int,后面参数int defaultvalue 干嘛的不知道……
i = intent.getIntExtra("choose", 0);
System.out.println("i------>"+i);
detailview = (TextView)findViewById(R.id.detailview);
//读入txt资源,创建输入流
InputStream is = getResources().openRawResource(R.raw.introduction);
//创建字符创存放缓存
byte[] buffer = new byte[1024];
int rd = 0;
//新建输出流
ByteArrayOutputStream output = new ByteArrayOutputStream();
//读取文本文件到缓存中
try{
while((rd = is.read(buffer)) != -1){
output.write(buffer, 0, rd);
}
//简体中文编码GBK,繁体big5?
String temp = new String(output.toByteArray(),"GBK");
//将获得字符串拆开,截取各段内容赋给string[]数组---trim去掉两边空白字符后的字符串---split分割函数
String[] detail = temp.trim().split("#");
detailview.setText(detail[i]);
//关闭输出流
output.close();
} catch (IOException e){
e.printStackTrace();
}
backbutton = (Button)findViewById(R.id.backbutton);
backbutton.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
linkbutton = (Button)findViewById(R.id.linkbutton);
linkbutton.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(detailActivity.this, linkActivity.class);
intent.putExtra("i", i);//直接传输网址的数组位置,不用+1
detailActivity.this.startActivity(intent);
}
});
}
}这个activity的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/detailview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dp"
/>
<Button
android:id="@+id/linkbutton"
android:layout_below="@id/detailview"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/linkbutton"
android:paddingTop="10dp"
/>
<Button
android:id="@+id/backbutton"
android:padding="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/backbutton"
/>
</RelativeLayout>请问是出现什么问题了……Manifest里面也注册了啊!
03-27 01:50:27.592: E/AndroidRuntime(316): java.lang.RuntimeException: Unable to start activity ComponentInfo{mars.product/mars.product.detailActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.os.Looper.loop(Looper.java:123)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-27 01:50:27.592: E/AndroidRuntime(316): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 01:50:27.592: E/AndroidRuntime(316): at java.lang.reflect.Method.invoke(Method.java:521)
03-27 01:50:27.592: E/AndroidRuntime(316): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-27 01:50:27.592: E/AndroidRuntime(316): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-27 01:50:27.592: E/AndroidRuntime(316): at dalvik.system.NativeStart.main(Native Method)
03-27 01:50:27.592: E/AndroidRuntime(316): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ListActivity.onContentChanged(ListActivity.java:245)
03-27 01:50:27.592: E/AndroidRuntime(316): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.Activity.setContentView(Activity.java:1647)
03-27 01:50:27.592: E/AndroidRuntime(316): at mars.product.detailActivity.onCreate(detailActivity.java:22)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-27 01:50:27.592: E/AndroidRuntime(316): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-27 01:50:27.592: E/AndroidRuntime(316): ... 11 more不好意思啊~~~
改成public class detailActivity extends Activity {}
可能是因为前一个activity是继承于ListActivity的,新建是把import之类的复制过去之后忘记删了TTATT之前一直以为是流读取那里有问题,下面的代码都看烂了都没有细看上面= =|||囧rz……问题已经解决啦!万分感谢!