moin moin
1.Activity:
package de.FH_APP;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
//import android.widget.ListView;
public class fh extends Activity {
private final String urlString = "http://www.blubb.php";
private final String TAG = fh.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView liste = (ListView) findViewById(R.id.liste);
byte buffer[] = new byte[1024];
try {
URL url = new URL(urlString);
InputStream is = url.openStream();
int numBytes = is.read(buffer);
is.close();
String entityContent = new String(buffer, 0, numBytes);
String[] eintrag = entityContent.split("@");
liste.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, eintrag));
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i(TAG, e.getMessage());
e.printStackTrace();
}
liste.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
TextView eintrag = (TextView) view;
Intent i = new Intent(fh.this, test1.class);
i.putExtra("eintrag", eintrag.getText());
startActivity(i);
}
});
}
public void onCreate1(Bundle icicle) {
super.onCreate(icicle);
ImageView fh = new ImageView(this);
fh.setImageResource(R.drawable.fhb_logo);
setContentView(fh);
}
}
Alles anzeigen
die xml dazu:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imageview" android:src="@drawable/fhb_logo"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" />
<ListView android:id="@+id/liste" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Alles anzeigen
2. Activity:
package de.FH_APP;
import android.app.ListActivity;
import android.os.Bundle;
//import android.widget.ArrayAdapter;
import android.widget.ImageView;
//import android.widget.ListView;
import android.widget.TextView;
public class test1 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
TextView textview = (TextView) findViewById(R.id.textView);
textview.setText(getIntent().getExtras().getString("eintrag"));
}
public void onCreate1(Bundle icicle) {
super.onCreate(icicle);
ImageView fh = new ImageView(this);
fh.setImageResource(R.drawable.fhb_logo);
setContentView(fh);
}
}
Alles anzeigen
die xml dazu:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imageview" android:src="@drawable/fhb_logo"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" />
<TextView android:layout_height="wrap_content" android:id="@+id/textView"
android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Alles anzeigen
und die Fehlermeldung in der Logcat:
"06-21 08:10:52.796: ERROR/AndroidRuntime(221): Uncaught handler: thread main exiting due to uncaught exception
06-21 08:10:52.844: ERROR/AndroidRuntime(221): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.FH_APP/de.FH_APP.fh}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.os.Looper.loop(Looper.java:123)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at java.lang.reflect.Method.invoke(Method.java:521)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at dalvik.system.NativeStart.main(Native Method)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ListActivity.onContentChanged(ListActivity.java:236)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.Activity.setContentView(Activity.java:1622)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at de.FH_APP.fh.onCreate(fh.java:55)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-21 08:10:52.844: ERROR/AndroidRuntime(221): ... 11 more
"
liegt es wirklich an der ListView oder woran?oO
gruß chuky