このコードに問題があります。リストビュー項目のクリックで定義されている URL にアクセスできません。null ポインター例外が発生しました。インターネットの許可を作成しました。
これは私のコードです
ジャワ
public class UGSimpliyBeta extends Activity {
ListView list_utama;
Intent intent;
WebView web;
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_PROGRESS);
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ugsimpliy_beta);
list_utama = (ListView)findViewById(R.id.list_utama);
web = (WebView)findViewById(R.id.webview);
String list_content[] = new String[]{"UG Web Service", "Schedule Service", "Exam Service", "Studentsite News", "About"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, list_content)
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
TextView textView=(TextView) view.findViewById(android.R.id.text1);
/*YOUR CHOICE OF COLOR*/
textView.setTextColor(Color.WHITE);
return view;
}
};
list_utama.setAdapter(adapter);
list_utama.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id)
{
Object item = parent.getItemAtPosition(pos);
String content = item.toString();
if(content.equals("UG Web Service"))
{
Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT).show();
}
else if(content.equals("Schedule Service"))
{
Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT).show();
}
else if(content.equals("Exam Schedule"))
{
Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT).show();
}
else if(content.equals("Studentsite News"))
{
Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT).show();
setContentView(R.layout.webview);
final Activity activity = UGSimpliyBeta.this;
final ProgressDialog progressdialog = new ProgressDialog(activity);
progressdialog.setCancelable(true);
web.setWebViewClient(new WebViewClient());
web.setWebChromeClient(new WebChromeClient()
{
public void onProgressChanged(WebView view, int progress)
{
progressdialog.show();
progressdialog.setProgress(0);
activity.setProgress(progress * 1000);
if(progress == 100 && progressdialog.isShowing())
{
progressdialog.dismiss();
}
}
});
web.loadUrl("https://www.studentsite.gunadarma.ac.id/news/news.php");
}
else
{
Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT).show();
intent = new Intent(UGSimpliyBeta.this, About.class);
startActivity(intent);
}
}
});
}
webview.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars = "none">
</WebView>
activity_ugsimply_beta.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"
android:background = "@drawable/tile">
<ImageView
android:layout_width = "200px"
android:layout_height = "200px"
android:layout_above = "@+id/title"
android:layout_centerHorizontal = "true"
android:layout_centerVertical = "true"
android:src = "@drawable/app"/>
<TextView
android:id = "@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity = "center"
android:textColor="#ffffff"
android:text="@string/hello_world"
tools:context=".UGSimpliyBeta" />
<ListView
android:id = "@+id/list_utama"
android:layout_width="fill_parent"
android:layout_height = "wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal = "true"
android:layout_centerVertical = "true"
android:cacheColorHint="#00000000"/>
</RelativeLayout>
これはlogcat用です
12-06 20:59:27.277: E/AndroidRuntime(3760): FATAL EXCEPTION: main
12-06 20:59:27.277: E/AndroidRuntime(3760): java.lang.NullPointerException
12-06 20:59:27.277: E/AndroidRuntime(3760): at com.rk.ug_simplify.UGSimpliyBeta$2.onItemClick(UGSimpliyBeta.java:69)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.widget.AbsListView$1.run(AbsListView.java:3168)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.os.Handler.handleCallback(Handler.java:605)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.os.Handler.dispatchMessage(Handler.java:92)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.os.Looper.loop(Looper.java:137)
12-06 20:59:27.277: E/AndroidRuntime(3760): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-06 20:59:27.277: E/AndroidRuntime(3760): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 20:59:27.277: E/AndroidRuntime(3760): at java.lang.reflect.Method.invoke(Method.java:511)
12-06 20:59:27.277: E/AndroidRuntime(3760): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-06 20:59:27.277: E/AndroidRuntime(3760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-06 20:59:27.277: E/AndroidRuntime(3760): at dalvik.system.NativeStart.main(Native Method)
エラーの原因と修正方法は?ありがとう。